Quick start manual
7-20
Delphi Language Guide
Properties
Array properties
Array properties are indexed properties. They can represent things like items in a list,
child controls of a control, and pixels of a bitmap.
The declaration of an array property includes a parameter list that specifies the
names and types of the indexes. For example,
property Objects[Index: Integer]: TObject read GetObject write SetObject;
property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
property Values[const Name: string]: string read GetValue write SetValue;
The format of an index parameter list is the same as that of a procedure’s or
function’s parameter list, except that the parameter declarations are enclosed in
brackets instead of parentheses. Unlike arrays, which can use only ordinal-type
indexes, array properties allow indexes of any type.
For array properties, access specifiers must list methods rather than fields. The
method in a read specifier must be a function that takes the number and type of
parameters listed in the property’s index parameter list, in the same order, and
whose result type is identical to the property’s type. The method in a write specifier
must be a procedure that takes the number and type of parameters listed in the
property’s index parameter list, in the same order, plus an additional value or const
parameter of the same type as the property.
For example, the access methods for the array properties above might be declared as
function GetObject(Index: Integer): TObject;
function GetPixel(X, Y: Integer): TColor;
function GetValue(const Name: string): string;
procedure SetObject(Index: Integer; Value: TObject);
procedure SetPixel(X, Y: Integer; Value: TColor);
procedure SetValue(const Name, Value: string);
An array property is accessed by indexing the property identifier. For example, the
statements
if Collection.Objects[0] = nil then Exit;
Canvas.Pixels[10, 20] := clRed;
Params.Values['PATH'] := 'C:\BIN';
correspond to
if Collection.GetObject(0) = nil then Exit;
Canvas.SetPixel(10, 20, clRed);
Params.SetValue('PATH', 'C:\BIN');
On Linux, you would use a path such as ‘/bin’ in place of ‘C:\BIN’ in the above
example.