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
Add Adds a key-value pair to the dictionary. If the key already exists, its value is updated.
AsDictionary Returns an IDictionary interface adapter for this ordered dictionary.
Clear Removes all key-value pairs from the dictionary.
ContainsKey Determines whether the dictionary contains the specified key.
Count Returns the number of key-value pairs in 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.
GetEnumerator Returns an enumerator to iterate over all key-value pairs in insertion order.
IndexOfKey Returns the zero-based index of the specified key, or -1 if not found.
Remove Removes the entry with the specified key from the dictionary.
Sort Overloaded
Sort
Sort()
TryGetValue Attempts to retrieve the value associated with the specified key.

Properties

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