Delphi>请解释一下:类型…对象的过程
发布时间:2020-12-15 04:08:59 所属栏目:大数据 来源:网络整理
导读:我遇到了一些对我来说很新的代码…… 我从来没有真正看到过对象过程的类型声明,我只是没有 明白这一点. 为什么开发人员不能只保留Boolean类型的字段? interface type TFinishedCaptureEvent = procedure(AFinished: Boolean) of object; TFrameCard = class
我遇到了一些对我来说很新的代码……
我从来没有真正看到过对象过程的类型声明,我只是没有 interface type TFinishedCaptureEvent = procedure(AFinished: Boolean) of object; TFrameCard = class(TFrame) ... private FOnFinishedCapture: TFinishedCaptureEvent; procedure DoUpdateMessage(AMessageType: TMessageType); public property OnFinishedCapture: TFinishedCaptureEvent read FOnFinishedCapture write FOnFinishedCapture; end; implementation ... procedure TFrameCard.DoUpdateMessage(AMessageType: TMessageType); begin if Assigned(FOnFinishedCapture) then FOnFinishedCapture(False); ... end; end. 解决方法
对象的过程是类实例中包含的过程的过程参考.调用作为类成员的过程时,必须使用其他参数传递implict Self引用.使用对象的过程告诉编译器将Self引用与过程引用中的过程地址一起存储,这样当通过过程引用调用过程时,将自动传递Self引用.
在您提供的代码片段中,TFinishedCaptureEvent被定义为对象的过程,这意味着其类型创建的任何变量将包含2个值:Self值和过程地址.分配此变量时,特别是当赋值在类中时,编译器将自动将此变量内的Self值设置为包含分配给变量的过程的类的实例.调用变量(FOnFinishedCapture(False))时,编译器会自动将正确的Self值传递回分配给此变量的过程. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |