From RAD Studio API Documentation
Jump to: navigation, search



TObjectDictionary<TKey,TValue> = class(TDictionary<TKey,TValue>)


template<typename TKey, typename TValue> class PASCALIMPLEMENTATION TObjectDictionary__2 : public TDictionary__2<TKey,TValue>


Type Visibility Source Unit Parent
class public
System.Generics.Collections System.Generics.Collections


Collection of key and/or value objects.

TObjectDictionary represents a generic collection of key and/or value objects. It can handle keys as objects, values as objects, or both as objects.

TObjectDictionary has the capability to handle objects' lifetime automatically. When a TObjectDictionary is instantiated, an Ownerships parameter specifies whether the dictionary owns the keys, values, or both. In the Create method, the type arguments are checked dynamically. If no Ownership is specified (the empty set), then the functionally of TObjectDictionary is identical to that of TDictionary.

Access methods

This section summarizes methods for reading and writing TDictionary or TObjectDictionary, including the effect of duplicate keys when writing, or key not found when reading.


Method Index type Value type If duplicate key
Add TKey TValue Exception
AddOrSetValue TKey TValue Overwrite
Items TKey TValue Overwrite


Method Index/input type Result type If key not found Notes
ContainsKey TKey Boolean false True = found
ContainsValue TValue Boolean n/a True = found
ExtractPair TKey TPair Default pair Returns TPair, removes item from dictionary
Items TKey TValue Exception Use TryGetValue to avoid exception
operator [] TKey TValue Exc C++ only
Keys n/a TKeyCollection n/a
ToArray n/a TArray<TPair<TKey,TValue>> n/a
TryGetValue TKey TValue, Boolean default,false Like Items[] without exception
Values n/a TValueCollection n/a

See Also