[fpc-pascal] Is it possible to know the data type of a specialized generics class?
Sven Barth
pascaldragon at googlemail.com
Tue Sep 24 11:25:04 CEST 2013
Am 24.09.2013 11:19, schrieb Xiangrong Fang:
> Hi All,
>
> say, I have a class TTree<T>; in the destructor of that class, is it
> possible to know the actual type of T? I want to do things like:
>
> generic TTree<T> = class
> public
> Data: T;
> destructor Destroy; override;
> end;
>
> destructor TTree.Destroy;
> begin
> ... ...
> if Data is TObject then Data.Free;
> end;
>
> But "is" does not work with generic types.
>
Short answer: No
Long answer: You could try to use TypeInfo(Data) or TypeInfo(T) and use
the returned PTypeInfo to find out the type...
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130924/c47f5b67/attachment.html>
More information about the fpc-pascal
mailing list