Table of Contents

TOrderedDictionary<K, V> Class

A generic dictionary that preserves the insertion order of key-value pairs.

Remarks

Unlike TDictionary, this class maintains items in the order they were added, allowing indexed access to keys and values by position. It also supports sorting the entries. Lookup by key uses a linear scan, so it is best suited for smaller collections where insertion order matters.

Syntax

Unit: Bcl.Collections

TOrderedDictionary<K, V> = class(TObject);

Type Parameters

Type Parameter Description
K The type of keys in the dictionary.
V The type of values in the dictionary.

Constructors

Name Description
Create Overloaded
Create
Create()

Methods

Name Description
AsDictionary Returns an IDictionary interface adapter for this ordered dictionary.
GetEnumerator Returns an enumerator to iterate over all key-value pairs in insertion order.
Sort Overloaded
Sort
Sort()
Clear Removes all key-value pairs from the dictionary.
Add Adds a key-value pair to the dictionary. If the key already exists, its value is updated.
Remove Removes the entry with the specified key from the dictionary.
Delete Removes the entry at the specified index.
ExtractPair Removes and returns the key-value pair for the specified key without triggering ownership notifications.
ContainsKey Determines whether the dictionary contains the specified key.
IndexOfKey Returns the zero-based index of the specified key, or -1 if not found.
TryGetValue Attempts to retrieve the value associated with the specified key.
Count Returns the number of key-value pairs in the dictionary.

Properties

Name Description
Values[const index] Gets the value at the specified index position.
Keys[const index] Gets the key at the specified index position.
Items[const key] Gets or sets the value associated with the specified key.