[fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Xiangrong Fang
Hi All, say, I have a class TTreeT; in the destructor of that class, is it possible to know the actual type of T? I want to do things like: generic TTreeT = class public Data: T; destructor Destroy; override; end; destructor TTree.Destroy; begin ... ... if Data is TObject then

Re: [fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Sven Barth
Am 24.09.2013 11:19, schrieb Xiangrong Fang: Hi All, say, I have a class TTreeT; in the destructor of that class, is it possible to know the actual type of T? I want to do things like: generic TTreeT = class public Data: T; destructor Destroy; override; end; destructor TTree.Destroy;

Re: [fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Sven Barth
Am 24.09.2013 11:25, schrieb Sven Barth: Am 24.09.2013 11:19, schrieb Xiangrong Fang: Hi All, say, I have a class TTreeT; in the destructor of that class, is it possible to know the actual type of T? I want to do things like: generic TTreeT = class public Data: T; destructor Destroy;

Re: [fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Xiangrong Fang
But it's not a good idea as you'd still need to convert Data to a TObject (e.g. by using a cast), but that will fail if Data is something else than a pointer-like type... This worked in my TTree class (destructor): if PTypeInfo(TypeInfo(Data))^.Kind = tkObject then TObject(Data).Free; I

Re: [fpc-pascal] Is it possible to know the data type of a specialized generics class?

2013-09-24 Thread Sven Barth
Am 24.09.2013 11:53, schrieb Xiangrong Fang: But it's not a good idea as you'd still need to convert Data to a TObject (e.g. by using a cast), but that will fail if Data is something else than a pointer-like type... This worked in my TTree class (destructor): if