Delphi Interposer类中的事件分配

Delphi Interposer类中的事件分配,第1张

概述我写了一个TEdit后代,它像这样处理OnExit事件 unit MyCustomEdit;interfaceuses Classes, StdCtrls;type TMyCustomEdit=class(TEdit) private procedure MyExit(Sender: TObject); public constructor Create(AOwn 我写了一个TEdit后代,它像这样处理OnExit事件

unit MyCustomEdit;interfaceuses  Classes,StdCtrls;type TMyCustomEdit=class(TEdit) private  procedure MyExit(Sender: TObject); public  constructor Create(AOwner: TComponent); overrIDe; end;implementation{ TMyCustomEdit }uses Dialogs;constructor TMyCustomEdit.Create(AOwner: TComponent);begin  inherited;  OnExit:=MyExit;end;procedure TMyCustomEdit.MyExit(Sender: TObject);begin  ShowMessage('Hello from TMyCustomEdit');//this is show only when is not assignated a event handler in the onexit event.end;end.

在我的应用程序的主要形式上,我正在使用Interposer类

unit UnitTest;interfaceuses  WinAPI.windows,WinAPI.Messages,System.SysUtils,System.Variants,System.Classes,Vcl.Graphics,Vcl.Controls,Vcl.Forms,Vcl.Dialogs,Vcl.StdCtrls,MyCustomEdit;type  TEdit=class (TMyCustomEdit);  TFormTest = class(TForm)    Edit1: TEdit;    Edit2: TEdit;    procedure Edit1Exit(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  FormTest: TFormTest;implementation{$R *.dfm}procedure TFormTest.Edit1Exit(Sender: TObject);begin   ShowMessage('Hello from TFormTest');//this code is always executedend;end.

现在我希望当在主窗体中分配Onexit事件时,我执行了我自己的TMyCustomEdit的onexit实现以及TFormTest窗体的OnExit事件的代码.但是当我运行代码时,只执行TFormTest.OnExit事件的代码.我如何能够执行哪两个方法实现?

解决方法 覆盖 DoExit.这是在控件失去焦点时调用的方法,它触发OnExit事件.根据您的需求,在之前或之后调用继承的DoExit:

procedure TMyCustomEdit.DoExit;begin  // Code here will run before the event handler of OnExit is executed  inherited DoExit; // This fires the OnExit event,if assigned  // Code here will run after the event handler of OnExit is executedend;
总结

以上是内存溢出为你收集整理的Delphi Interposer类中的事件分配全部内容,希望文章能够帮你解决Delphi Interposer类中的事件分配所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1268181.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-08
下一篇2022-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存