Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-02

Generics, TObject Descendant?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Den

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?

- Dennis

Reply by email

Sven Barth
to Den
Den wrote 14 lines
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

Reply by email

Den
to Sven Barth

Ahh, thanks Sven! I'll see if I can post a bug report soon of it.. I'll use the work-around for now. :)

Sven Barth wrote 47 lines
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 _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email