Recent

Author Topic: Add members to a specialized generic class  (Read 2934 times)

simone

  • Hero Member
  • *****
  • Posts: 573
Add members to a specialized generic class
« 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?
« Last Edit: April 21, 2017, 02:32:27 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Add members to a specialized generic class
« Reply #1 on: April 21, 2017, 03:25:25 pm »
Code: Pascal  [Select][+][-]
  1. TMyLyst = class(specialize TFPGObjectList<TMyClass>)
  2.   procedure proc1;
  3. end;
  4.  
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Add members to a specialized generic class
« Reply #2 on: April 21, 2017, 04:02:59 pm »
Simple and compact solution! Thanks!
« Last Edit: April 21, 2017, 04:11:51 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018