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

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

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

Classes and objects

inherited Destroy;

end;

析构函数的最后一步,通常是调用继承下来的析构函数,用来销毁继承的字段。

When an exception is raised during creation of an object, Destroy is automatically called to dispose of the unfinished object. This means that Destroy must be prepared to dispose of partially constructed objects. Because a constructor sets the fields of a new object to zero or empty values before performing other actions, class-type and pointer-type fields in a partially constructed object are always nil. A destructor should therefore check for nil values before operating on class-type or pointer-type fields. Calling the Free method (defined in TObject), rather than Destroy, offers a convenient way of checking for nil values before destroying an object.

当创建对象时发生了异常,会自动调用析构函数来清除不完整的对象,这表示析构函数必须准备好来清除只构建了一部分的对象。因为构造函数在执行其它动作之前先设置新对象的字段为0或空值,在一个只构建了一部分的对象中,类类型和指针类型的字段总是nil,所以,在操作类类型和指针类型的字段时,析构函数必须检查它们是否为nil。销毁一个对象时调用Free方法(在TObject中定义)而不是Destroy会更加方便,因为前者会检查对象是否为nil。

Message methods(Message方法)

Message方法用来响应动态分派的消息。Message方法在各个平台上都是支持的,VCL使用message方法来响应Windows消息,CLX不使用message方法来响应系统事件。

在声明方法时,通过包含message指示字来创建一个message方法,并在message后面跟一个介于1到49151之间的整数常量,它指定消息的号码(ID)。对于VCL控件(control),message方法中的整数常量可以是Messages单元中定义的Windows消息号码,这里还定义了相应的记录类型。一个message方法必须是具有一个单一var参数的过程。

比如,在Windows下:

type

TTextBox = class(TCustomControl)

private

procedure WMChar(var Message: TWMChar); message WM_CHAR;

...

end;

比如,在Linux或在跨平台的情况下,你要以如下方式处理消息:

const

ID_REFRESH = $0001;

type

TTextBox = class(TCustomControl)

private


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23665-78.html

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

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