E2017 列表所需的指针类型
E2017 Pointer type required for List
从DelphiWin XP下的2007到Win7下的Xe7,
我不确定为什么这条突出显示的行不起作用
Error : [dcc32 Error] utilmemblock.pas(935): E2017 Pointer type required
//D:Convert a memory block to a List. Odd sizes are truncated.
procedure MemBlockToList(const MemBlock:TMemBlock;List:TList);
var
Size:Integer;
begin
Size:=(MemBlock.Size div SizeOf(Pointer));
List.Count:=Size;
Move(MemBlock.Block^,List.Last^,Size*SizeOf(Pointer)); // This error points to this line
end;
我已经检查过这个 related question 但我不知道如何将它应用到我的问题中。
假设陈述
- 我假设
MemBlock
是您可以控制的类型,因此不是错误的来源。
- 我假设
List.Last
实际上是 List.List
。
答案,基于这些假设
在旧的 Delphi 版本中 TList.List
是一个指向静态数组的指针。在现代 Delphi TList.List
中已更改为 TPointerList
类型的动态数组,其中
TPointerList = array of Pointer;
所以你的代码应该是
Move(MemBlock.Block^, Pointer(List.List)^, Size*SizeOf(Pointer));
从DelphiWin XP下的2007到Win7下的Xe7,
我不确定为什么这条突出显示的行不起作用
Error : [dcc32 Error] utilmemblock.pas(935): E2017 Pointer type required
//D:Convert a memory block to a List. Odd sizes are truncated.
procedure MemBlockToList(const MemBlock:TMemBlock;List:TList);
var
Size:Integer;
begin
Size:=(MemBlock.Size div SizeOf(Pointer));
List.Count:=Size;
Move(MemBlock.Block^,List.Last^,Size*SizeOf(Pointer)); // This error points to this line
end;
我已经检查过这个 related question 但我不知道如何将它应用到我的问题中。
假设陈述
- 我假设
MemBlock
是您可以控制的类型,因此不是错误的来源。 - 我假设
List.Last
实际上是List.List
。
答案,基于这些假设
在旧的 Delphi 版本中 TList.List
是一个指向静态数组的指针。在现代 Delphi TList.List
中已更改为 TPointerList
类型的动态数组,其中
TPointerList = array of Pointer;
所以你的代码应该是
Move(MemBlock.Block^, Pointer(List.List)^, Size*SizeOf(Pointer));