我需要移動存儲的字節數組一套位於從TList記錄中的數據,但我得到這個錯誤如何使用移動過程填充TList <T>元素?
E2197常量對象不能作爲變量參數傳遞
此代碼重現此問題。
uses
System.Generics.Collections,
System.SysUtils;
type
TData = record
Age : Byte;
Id : Integer;
end;
//this code is only to show the issue, for simplicity i'm filling only the first
//element of the TList but the real code needs fill N elements from a very big array.
var
List : TList<TData>;
P : array [0..1023] of byte;
begin
try
List:=TList<TData>.Create;
try
List.Count:=1;
//here i want to move the content of the P variable to the element 0
Move(P[0],List[0], SizeOf(TData));
finally
List.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
我怎樣才能一個緩衝器的內容複製到一個元素的TList
定義「需要」?看來你應該說「想要」。 –