Canvas.Pixels[10, 20] := clRed;
Params.Values['PATH'] := 'C:\DELPHI\BIN';
对应于
- 110 -
Classes and objects
if Collection.GetObject(0) = nil then Exit;
Canvas.SetPixel(10, 20, clRed);
Params.SetValue('PATH', 'C:\DELPHI\BIN');
在Linux下,上面的例子你要使用像“/usr/local/bin”的路径取代“C:\DELPHI\BIN”。
定义数组属性时可以在后面使用default指示字,此时,数组属性变成类的默认属性。比如, type
TStringArray = class
public
property Strings[Index: Integer]: string ...; default;
...
end;
若一个类有默认属性,你能使用缩写词object[index]来访问这个属性,它就相当于object.property[index]。比如,给定上面的声明,StringArray.Strings[7]可以缩写为StringArray[7]。一个类只能有一个默认属性,在派生类中改变或隐藏默认属性可能导致无法预知的行为,因为编译器总是静态绑定一个对象地默认属性。
Index specifiers(索引限定符)
索引限定符能使几个属性共用同一个访问方法来表示不同的值。索引限定符包含index指示字,并在后面跟一个介于-2147483647到2147483647之间的整数常量。若一个属性有索引限定符,它的读写限定符必须是方法而不能是字段。比如,
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;
对于有索引限定符的属性,它的访问方法必须有一个额外的整数类型的值参:对于读取函数,它必须是最后一个参数;对于写入过程,它必须是倒数第2个参数(在指定属性值的参数之前)。当程序访问属性时,属性的整数常量自动传给访问方法。
给出上面的声明,若Rectangle属于TRectangle类型,则
Rectangle.Right := Rectangle.Left + 100;
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23665-82.html
我相信没错