如何确定Delphi
procedure TTableData<T>.Delete(Index: Integer);
begin
if Items[Index] is TClass then TClass(Items[Index]).Free;
inherited Delete(Index);
end;
答案 0 :(得分:2)
您可以这样使用RTTI:
uses
System.TypInfo;
....
procedure TTableData<T>.Delete(Index: Integer);
var
item: T;
begin
if PTypeInfo(TypeInfo(T)).Kind = tkClass then
begin
item := Items[index];
TObject((@item)^).Free;
end;
inherited Delete(Index);
end;