Author
Topic: TFPGList vs TFPGObjectList in FGL (Read 489 times)

What is the difference between TFPGList and TFPGObjectList in FGL? I know that with TFPGObjectList it is possible to set the ownership of objects, allowing automatic freeing. Are there any other significant differences? Thanks.

That's indeed the difference between them (just like TList and TObjectList). In 3.2 and newer TFPGObjectList will even explicitely reject specializations with anything that's not a descendant of TObject.

Thanks PascalDragon. I'm not sure to understand. In TList (belonging to RTL), items are pointers, whereas in TObjectList (in FCL) they are objects. Moreover in the TList I can't set not ownership of items, conversely in TObjectList I can. Now in FGL implementation of generics, both TFPGList and TFPGObjectList require that items are objects (i.e. descendants of TObject). As a conseguence, metatype T can't be specialized with a record. Differently, in rtl-generics implementation, specialization with a record type is supported. So, what is the impact of change you are talking about? Thanks again for kind support.

In common OOP terminology, object is class instance.Unfortunately, as Borland's legacy, FPC has another usage of the same term.

I'm not saying that old-style objects don't have their place still. I think that not following Delphi in deprecating them is a FPC team's good decision.However, in modern FPC usage, as well as in Delphi, the old style objects are not common. In Delphi they are even deprecated, so the main usage of the term is just -- class instance.

When talking about objects in different meaning, only then I would add some attribute -- old style objects, old objects, legacy objects, TP-style objects, ...

Thanks PascalDragon. I'm not sure to understand. In TList (belonging to RTL), items are pointers, whereas in TObjectList (in FCL) they are objects. Moreover in the TList I can't set not ownership of items, conversely in TObjectList I can. Now in FGL implementation of generics, both TFPGList and TFPGObjectList require that items are objects (i.e. descendants of TObject). As a conseguence, metatype T can't be specialized with a record. Differently, in rtl-generics implementation, specialization with a record type is supported. So, what is the impact of change you are talking about? Thanks again for kind support.

No, TFPGList does not require your items to be descendants of TObject. The only requirement is that a = operator is available for the type (Note: global operators don't work, for records it needs to be part of the type).And the impact is only that TFPGObjectList explicitely checks for descendants of TObject, before that it was implicitely.

Since in my code operator oveloading of = has been correctly done for conventional record, does it means that in FGL specialization is only possible using advanced record with has been correctly done overload, but is not available for conventional record?