Name
Array Keyword
Syntax
typeName= array[Index type] ofBase type; // static array type typeName= array[Index type, ...] ofBase type; // static array type typeName= array ofBase type; // dynamic array typeName: array ofBase type// open array as a subroutine parameterName: 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
Integerand whose size can change while the program runs. The lower bound of the index is always zero, and the upper bound is set with theSetLengthprocedure. To copy a dynamic array, call theCopyprocedure. 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access