Recent

Author Topic: Does TFPSList.Clear Free the Objects in it ?  (Read 1302 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Does TFPSList.Clear Free the Objects in it ?
« on: October 27, 2021, 12:48:40 pm »
Hello,

Does "TFPSList.Clear" Free all my Objects in the List ?
I have not quite understood the definition (https://lazarus-ccr.sourceforge.io/docs/rtl/fgl/tfpslist.clear.html).
I want to Free them by Myself.

Thanks in advance. :)

EDIT: Do i have to use Extract for all my Items if i want to keep them ?
« Last Edit: October 27, 2021, 12:51:46 pm by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: Does TFPSList.Clear Free the Objects in it ?
« Reply #1 on: October 27, 2021, 12:56:27 pm »
This Basic List have not implemented 'property FreeObjects: Boolean;' so you MUST delete the Objects by yourself before clear the list.

Quote
TFPSList can be seen as the generalized equivalent of the classes unit TFPList list. It is used as a base class for the TFPGList, TFPGMap, TFPGObjectList, TFPGInterfacedObjectList and TFPGMapInterfacedObjectData generic classes.
This list is not meant to be used directly, it is an auxiliary class for the actual generic list classes.

If you use TFPGObjectList then you can decide, the list owns the Objects and delete it, or you have to do this. Normally it is better you use a more specialized List (if you do not implement your own List) eg. TFPGObjectList.
« Last Edit: October 27, 2021, 12:59:23 pm by af0815 »
regards
Andreas

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Does TFPSList.Clear Free the Objects in it ?
« Reply #2 on: October 27, 2021, 01:02:40 pm »
I have a spezialized List (TBauteilListe = specialize TFPGObjectList<TBauteil>).

I have certain objects and fill my list with them. So if i want to clear my list but keep my Objects, how do i do it?

Should i work with Extract ? or is there Some Property i can set, so the List does not own the Objects, and i can just remove the references.
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: Does TFPSList.Clear Free the Objects in it ?
« Reply #3 on: October 27, 2021, 01:08:41 pm »
Use the FreeObjects property https://lazarus-ccr.sourceforge.io/docs/rtl/fgl/tfpgobjectlist.freeobjects.html (as mentioned in the post before) and set it to false direct after the Creation of the list.
regards
Andreas

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Does TFPSList.Clear Free the Objects in it ?
« Reply #4 on: October 27, 2021, 01:32:07 pm »
If i got it right then it should be done like this :

Code: Pascal  [Select][+][-]
  1.  
  2.    //Declare TMyList as specified TFPGObjectList
  3.    TMyList:= specialize TFPGObjectList<TMyObject>;
  4.    
  5.    //Set Property "FreeObjects" to False when list does get created
  6.    List:= TMyList.Create(False);
  7.  
  8.  

Thanks you very much @af0815 :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018