[fpc-pascal] Re: Inheriting from generics specialized classes

Sven Barth pascaldragon at googlemail.com
Thu Nov 24 17:16:05 CET 2011


Am 24.11.2011 17:10, schrieb Juha Manninen:
> Now, if I do:
>
>    myV := TMyDerived.Create(False);
>    if myV is TFPGObjectList then
>      ...
>
> it gives:
>   unit1.pas(67,10) Error: Class or Object types "TMyDerived" and
> "TFPGObjectList" are not related
>
> In my opinion they are related.
>
> Maybe generics are good only for situations where you don't need to
> derive classes or test their inheritance.

They are not related. You should not think about generics as full 
classes. They are merely "templates". If you do a "specialize 
TFPGObjectList<SomeType>" the compiler will use the recorded declaration 
and implementation of the "TFPGObjectList", replace all occurences of 
the type "T" by "SomeType" and will parse the specialization as if you 
had written it like that yourself.

You'd need to check against your specialized "TMyGen" instead of 
"TFPGObjectList" then it would work.

In mode Delphi and my generic branch (I hope ^^) you are able to do it 
like this as well:

myV := TMyDerived.Create(False);
if myV is TFPGObjectList<TMyGen> then
   ...

Under the condition that "TMyDerived" is declared like in your previous 
mail.

Regards,
Sven




More information about the fpc-pascal mailing list