How to check if TypeIdenitifier(T) is an Object?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-24T16:34:39Z Indexed on 2010/04/24 16:53 UTC
Read the original article Hit count: 165

I'm creating a generic list class that has a member of type Array(Array of ). The problem is the class descruction,because the class is supposed to be used for types from byte to types inheriting TObject.

Specifically:

destructor Destroy;
var elem:T;
begin
  /*if(T is Tobject) then  //Check if T inherits TObject {Compiler error!}
    for elem in FData do TObject(elem).Free;*/    // do not know how to do it

  SetLength(FItems,0); //FItems : Array of T
  inherited Destroy;
end;

How do I check if T is TObject so I can free every member if the typeidenitifier is a class,for example?

© Stack Overflow or respective owner

Related posts about generics

Related posts about delphi