Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə177/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   173   174   175   176   177   178   179   180   ...   294
DelphiLanguageGuide

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


Rectangle.Right := Rectangle.Left + 100;
corresponds to
Rectangle.SetCoordinate(2, Rectangle.GetCoordinate(0) + 100);

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   173   174   175   176   177   178   179   180   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin