Index Specifiers Index specifiers allow several properties to share the same access method while representing different values. An
index specifier consists of the directive index followed by an integer constant between -2147483647 and
2147483647. If a property has an index specifier, its read and write specifiers must list methods rather than fields.
For example,
type
TRectangle = class
private
FCoordinates: array[0..3] of Longint;
function GetCoordinate(Index: Integer): Longint;
procedure SetCoordinate(Index: Integer; Value: Longint);
public
property Left: Longint index 0 read GetCoordinate write SetCoordinate;
property Top: Longint index 1 read GetCoordinate write SetCoordinate;
property Right: Longint index 2 read GetCoordinate write SetCoordinate;
property Bottom: Longint index 3 read GetCoordinate write SetCoordinate;
property Coordinates[Index: Integer]: Longint read GetCoordinate write SetCoordinate;
...
end;
An access method for a property with an index specifier must take an extra value parameter of type Integer. For a
read function, it must be the last parameter; for a write procedure, it must be the second-to-last parameter (preceding
the parameter that specifies the property value). When a program accesses the property, the property's integer
constant is automatically passed to the access method.
Given the declaration above, if
Rectangle
is of type
TRectangle
, then
153