Chapter 6 – Arrays and Collections
Chapter 6 of Delphi XE2 Foundations covers the essential data structures for grouping and iterating over values in Delphi: arrays, collections, and enumerators. These constructs form the backbone of efficient data management in Delphi applications.
Array Structures
Delphi provides several array types suited to different scenarios. Static arrays offer fixed-size, stack-allocated storage with strong compile-time guarantees. Dynamic arrays, allocated on the heap, can be resized at runtime using SetLength and are reference-counted for automatic memory management. Open arrays allow routines to accept arrays of varying lengths, while multi-dimensional arrays support tabular and matrix-style data layouts.
Collection Types and Enumerators
Beyond basic arrays, Delphi's runtime library includes rich collection classes. TList<T> and TObjectList<T> provide generic, type-safe list containers with methods for sorting, searching, and inserting. TDictionary<TKey,TValue> offers hash-based key-value storage. The chapter also explores the enumerator pattern, which enables for…in iteration over custom containers, making collection traversal both concise and readable.
What You'll Learn
- Choosing between static, dynamic, and open arrays
- Managing dynamic array lifetime and reference counting
- Working with multi-dimensional arrays
- Using generic collection classes from the RTL
- Implementing custom enumerators for
for…insupport