Lazarus

Programming => General => Topic started by: egsuh on October 20, 2020, 04:28:45 am

Title: [SOLVED] What's difference between TList and TObjectList?
Post by: egsuh on October 20, 2020, 04:28:45 am
And TFPGList and TFPGObjectList?

As far as I know, what really matters to me is that I do not have to free the objects with TObjectList myself.  Are there any differences?
Title: Re: What's difference between TList and TObjectList?
Post by: trev on October 20, 2020, 04:43:13 am
See this thread (https://forum.lazarus.freepascal.org/index.php?topic=46408.0).
Title: Re: What's difference between TList and TObjectList?
Post by: PascalDragon on October 20, 2020, 09:42:14 am

In general I nowadays suggest to use one of the generic lists as they're more typesafe. The Generics.Collections unit is provided with FPC only from 3.2.0 on, though it's also available externally for 3.0.4. I suggest to use the FGL classes if size is a concern (e.g. embedded applications on small systems) as the Generics.Collections are more heavyweight, but more versatile and - especially the dictionary classes - faster.
Title: Re: What's difference between TList and TObjectList?
Post by: ASerge on October 20, 2020, 08:00:04 pm
A few other lists are worth mentioning:
Classes.TFPList - The basic list of pointers. The lightest and fastest. Classes.TList uses it internally, adding code to track delete/insert events (at least for compatibility with Delphi). I've seen patches on Delphi that "remove" these tracking excesses from the TList to speed up. In FPC, this is not necessary.
Contnrs.TFPObjectList - inheritor from TFPList, while maintaining the same speed, similar in functionality to Contnrs.TObjectList. Some of the LCL and FCL components use it.
Title: Re: What's difference between TList and TObjectList?
Post by: egsuh on October 21, 2020, 05:53:00 am
Thank you for all your kind advices. It's not easy to grasp at once. I'll think over them which one is best for my purposes.
TinyPortal © 2005-2018