我有一个泛型列表,我想要放入一些记录或一些类
TMyList<T> = class
private
fCount: Cardinal;
fItems: array of T;
public
constructor Create(aSize: Integer);
procedure UpdateItem(const x: T);
end;
但是我无法编译
procedure TMyList<T>.UpdateItem(const x: T);
var
I: integer;
begin
for I := 0 to fCount - 1 do
if fItems[I] = x then begin // <- error E2015
//do update
break;
end;
end;
它适用于声明为TMyList<T : class> = class
的类,但随后它就无法再容纳记录了。
当然,我也声明了class operator Equal(Left, Right : TMyRecord) : Boolean;
来使MyRecord1 = MyRecord2
可以编译通过。