我正在尝试将Append
方法添加到System.Generics.Collections.TArray
类型。
unit uMyArray;
interface
uses
System.Generics.Collections;
type
TArray = class(System.Generics.Collections.TArray)
public
class procedure Append<T>(var AValues: array of T; const AItem: T); static;
end;
implementation
class procedure TArray.Append<T>(var AValues: array of T; const AItem: T);
begin
SetLength(AValues, Length(AValues) + 1);
AValues[Length(AValues) - 1] := AItem;
end;
end.
编译时,在SetLength
行上出现以下错误:
[[dcc32错误] uMyArray.pas(18):E2008不兼容的类型
您无法调整开放数组参数的大小。您需要传递TArray<T>
。
更改
class procedure Append<T>(var AValues: array of T; const AItem: T); static;
to
class procedure Append<T>(var AValues: TArray<T>; const AItem: T); static;