Lazarus

Free Pascal => General => Topic started by: simone on April 21, 2017, 01:05:09 pm

Title: Add members to a specialized generic class
Post by: simone on April 21, 2017, 01:05:09 pm
I have a doubt about generics. When I define a new class, as following

Code: Pascal  [Select][+][-]
  1. TMyLyst=specialize TFPGObjectList<TMyClass>

and I want to add to it some member (i.e. fields/properties/methods), for example:

Code: Pascal  [Select][+][-]
  1.   TMyLyst=specialize TFPGObjectList<TMyClass>
  2.     procedure proc1;
  3.   end;

I have a sintax error. To circumvent the problem I must to derive a subclass and then add to it the new members, as in the following:

Code: Pascal  [Select][+][-]
  1.   TDerivedMyList=class(TMyLyst)
  2.     procedure proc1;
  3.   end;

This is a desidered feauture of syntax or is an issue?
Title: Re: Add members to a specialized generic class
Post by: eny on April 21, 2017, 03:25:25 pm
Code: Pascal  [Select][+][-]
  1. TMyLyst = class(specialize TFPGObjectList<TMyClass>)
  2.   procedure proc1;
  3. end;
  4.  
Title: Re: Add members to a specialized generic class
Post by: simone on April 21, 2017, 04:02:59 pm
Simple and compact solution! Thanks!
TinyPortal © 2005-2018