Name

Array Keyword

Syntax

type Name = array[Index type] of Base type;        // static array type
type Name = array[Index type, ...] of Base type;   // static array type
type Name = array of Base type;                   // dynamic array type
Name: array of Base type        // open array as a subroutine parameter
Name: array of const    // open variant array as a subroutine parameter

Description

Delphi has several different kinds of arrays: static arrays, dynamic arrays, and open arrays:

  • A static array is a traditional Pascal array. You can use any ordinal type as an index, and an array can have multiple indices. The size of a static array cannot change at runtime.

  • A dynamic array is an array whose index type is Integer and whose size can change while the program runs. The lower bound of the index is always zero, and the upper bound is set with the SetLength procedure. To copy a dynamic array, call the Copy procedure. Assigning a dynamic array assigns a reference to the array without assigning the array’s contents. Delphi uses reference counting to manage the lifetime of dynamic arrays. Unlike strings, Delphi does not use copy-on-write for dynamic arrays.

  • A subroutine parameter can be an open array. You can pass any static or dynamic array to the subroutine. Delphi passes an additional, hidden parameter that gives the upper bound of the array. The subroutine cannot change the size of a dynamic array that is passed as an open array. Regardless of the index type of the actual array, the open array parameter uses an Integer ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.