b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

pascal 视频教程_pascal和basic_pascal选择排序(82)

电脑杂谈  发布时间:2016-12-28 07:02:37  来源:网络整理

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

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...