[fpc-devel] Generics, TObject Descendant?

Sven Barth pascaldragon at googlemail.com
Thu Feb 19 07:22:17 CET 2015


On 18.02.2015 20:51, Den wrote:
> Hi there,
>
> Currently this code:
>
>    TSomeObject<T> = Class;
>    TSomeOtherObject<T : TObject> = Class(TSomeObject<T> );
>
> And finally:
>
>    TMyObject = Class;
>    TSomeOtherOtherObject<T : TMyObject> = Class(TSomeOtherObject<T> );
>
> Comes up with error 'got "T" expected "TObject"' .. But TMyObject is
> based off of TObject?

At seems that there are still problems if TMyObject is merely a forward 
declaration... the following works:

=== code begin ===

type
   TSomeObject<T> = Class
   end;

   TSomeOtherObject<T : TObject> = Class(TSomeObject<T> );

   TMyObject = Class
   end;

   TSomeOtherOtherObject<T : TMyObject> = Class(TSomeOtherObject<T> );

=== code end ===

Note 1: this is a forward declaration "XYZ = class;", this is not: "XYZ 
= class(TObject);"
Note2 : a generic /must not/ be a forward declaration (in this case 
TSomeObject<T>).

A forward declaration of TMyObject should be valid in this case however, 
so please report a bug with an example program attached.

Regards,
Sven



More information about the fpc-devel mailing list