Object Containers

Beside the generic classes covered at the beginning of this section, there are also four inherited generic classes that are derived from the base classes defined in the Generics.Collections unit, mimicking existing classes of the Contnrs unit: type

TObjectList<T: class> = class(TList<T>) TObjectQueue<T: class> = class(TQueue<T>) TObjectStack<T: class> = class(TStack<T>)

Compared to their base classes, there are two key differences. One is that these generic types can be used only for objects; the second is that they define a customized Notification method, that in the case when an object is removed from the list (beside optionally calling the OnNotify event handler) will Free the object.

In other words, the TObjectList<T> class behaves like its non-generic counterpart when the OwnsObjects property is set. If you are wondering why this is not an option any more, consider that TList<T> can now be used directly to work with object types, unlike its non-generic counterpart.

There is also a fourth class, again, called TObjectDictionary<TKey, TValue>, which is defined in a different way, as it can own the key object, the value objects, or both of them. See the TDictionaryOwnerships set and the class constructor for more details.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment