Reputation: 799
I am using Delphi XE3. When searching helps for TObjectList, I find it appears in two units:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Contnrs.TObjectList
and
http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Generics.Collections.TObjectList
In such a case, which unit should I include to use the class? Also what is the different between TObjectList and TList, I just see TObjectList = class(TList) in the first document so TObjectList is identical to TList?
Thanks
Upvotes: 2
Views: 2449
Reputation: 596527
System.Contnrs.TObjectList
is the older legacy non-Generic version of a list of objects.
System.Generics.Collections.TObjectList<T>
is the newer Generic version.
See Overview of Generics.
Use whichever one suits your needs.
The non-Generic TList
is just a list of raw pointers. It does not do anything special with the pointers that are stored in it.
The non-Generic TObjectList
is derived from TList
to add extra handling of general purpose TObject
pointers, such as to add the OwnsObjects
property which allows the list to free stored objects when the list itself is freed.
The Generic TList<T>
is similar to, but not derived from, the non-Generic TList
, where T
can be any type, it does not even need to be a pointer (for example, TList<Integer>
).
The Generic TObjectList<T>
is similar to, but not derived from, the non-Generic TObjectList
, where T
can be any class type that is derived from TObject
.
Upvotes: 8