* * *

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

simone

  • Jr. Member
  • **
  • Posts: 61
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 »

eny

  • Hero Member
  • *****
  • Posts: 1558
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 1.4.2 'stable' (#49524 win32) unless specified otherwise...

simone

  • Jr. Member
  • **
  • Posts: 61
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 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus