[fpc-pascal] RTTI and generics: accessing specialized class instance

leledumbo leledumbo_cool at yahoo.co.id
Sat Oct 31 19:04:39 CET 2015

> You'll have the problem to know the specific class at compile time no
matter whether you use generics or inheritance

Not really, with inheritance, I can just cast the TObject returned by
GetObjectProp to the parent class (TGenClass). Because that's all I need:
accessing TGenClass members.

> If you want access to specific methods of the published then I suggest you
> to either have that class implement an interface or to have it inherit
> from a common base class that you can check for using "is" (yes, a generic
> can inherit from a normal class without problems).

Aha! That's right, I can implement the methods/fields/whatever in a normal
class which is then extended by the generic class. This is a hybrid
generics-inheritance approach, should've thought about it. Thanks for the

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/RTTI-and-generics-accessing-specialized-class-instance-tp5723011p5723016.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.

More information about the fpc-pascal mailing list