Recent

Author Topic: Specializing an ObjectList  (Read 1144 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Specializing an ObjectList
« on: October 26, 2021, 03:44:36 pm »
Hello

I tried to create an Objectlist, worked !

Next step was to Specialize the Object List and i got some strange error.
Here the Code:

Code: Pascal  [Select][+][-]
  1. uses contnrs, uTCar;
  2.  
  3. TCarLIst = specialize TObjectList<TCar>;
  4.  
  5. var
  6.    CarList: TCarList;
  7.  
  8.  
  9. Procedure Form.Create(Sender: TObject);
  10. begin
  11.    //CarList:= TCarList.Create;
  12.    CarList:= specialize TObjectList<TCar>
  13. end;
  14.  

After doing this i tried to access the List like this:

Code: Pascal  [Select][+][-]
  1.    CarList.
  2.  

When i tried to press Ctrl + Space, it jumped to this line:

Code: Pascal  [Select][+][-]
  1.    TCarList = specialize TObjectList<TCar>;
  2.  
 
and told me following: "General identifier expected but TObjectList found"

Tried the Code from this post:

https://forum.lazarus.freepascal.org/index.php?topic=43625.0

but did not work. am i missing Something ?

Any Help is welcome :)

EDIT: Works with TFPGObjectList... whats the difference. Source forge told me that TFPGObjectList is only for Specializing lists (if i understood it correctly). Could Someone please tell me the difference ? :)
« Last Edit: October 26, 2021, 04:05:04 pm by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Specializing an ObjectList
« Reply #1 on: October 26, 2021, 04:08:13 pm »
but did not work. am i missing Something ?
To work with generics and use the code you quoted you need to have FGL in your uses clause (not Contnrs) and specialize TFPGObjectList, not TObjectList (which is not generic).

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Specializing an ObjectList
« Reply #2 on: October 26, 2021, 04:09:34 pm »
but did not work. am i missing Something ?
To work with generics and use the code you quoted you need to have FGL in your uses clause (not Contnrs) and specialize TFPGObjectList, not TObjectList (which is not generic).

Thanks !! :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018