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

Sven Barth pascaldragon at googlemail.com
Sat Oct 31 09:36:23 CET 2015


Am 31.10.2015 05:31 schrieb "leledumbo" <leledumbo_cool at yahoo.co.id>:
>
> > TGenClass<> is not a full type, only TGenClass<Integer> is, so you need
to
> use - in your example - TSpecType(Obj)
>
> Yes, I'm aware of this. The problem is I don't know TSpecType which I said
> the last note. It could be any user defined specialization of TGenClass.
> Back to above code, but closer to my actual complex code:
>
[snip]
>
> I hope you can get the better picture. One solution is not to use generics
> and return to good old inheritance, but I'm still thinking if there's a
> solution without sacrificing the generics. I don't know how other
languages
> which has generics/templates solve this problem, though. Might be worth a
> research.

You'll have the problem to know the specific class at compile time no
matter whether you use generics or inheritance. 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).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151031/59e228d6/attachment.html>


More information about the fpc-pascal mailing list