我需要将存储在一个字节数组中的数据移动到位于TList中的一组记录,但是我收到了这个错误
E2197常量对象不能作为var参数传递
此代码重现了该问题 .
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;
P : array [0..1023] of byte;
begin
try
List:=TList.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元素