[翻译]Event Handler Description 事件处理描述

Event Handler Description 事件处理描述 (自定义控件)

How should a new event handler be defined if it does not already belong to the base class? Let's look at this using the “TfrxEditControl” common control as an example:

一个新的事件处理程序应该如何定义,如果它不属于基类?让我们看看使用“TfrxEditControl“控件为例:

TfrxEditControl = class(TfrxDialogControl)

private

FEdit: TEdit;

{ new event }

FOnChange: TfrxNotifyEvent;   //定义事件,注册类型。

procedure DoOnChange(Sender: TObject);   //事件处理过程

...

public

constructor Create(AOwner: TComponent); override;

...

published

{ new event }

property OnChange: TfrxNotifyEvent read FOnChange write FOnChange;  //定义事件

...

end;

constructor TfrxEditControl.Create(AOwner: TComponent);

begin

...

{ connect our handler }

FEdit.OnChange := DoOnChange;   //在Create中关联事件(把TEdit控件的事件关联到自己的过程中)

InitControl(FEdit);

...

end;

procedure TfrxEditControl.DoOnChange(Sender: TObject);

begin

{ call event handler }

if Report <> nil then

Report.DoNotifyEvent(Sender, FOnChange);   //处理事件(在过程中调用报表里的脚本)

end;

It is important to note that the event handler in FastReport is a procedure defined in the report script. The TfrxNotifyEvent type is declared as String[63] and in FastReport the link to the handler is a string containing its name. This is unlike the Delphi TNotifyEvent type, in which it is a method address.

很重要的提示,事件处理程序是在报表脚本中定义的过程。TfrxNotifyEvent 类型被声明为String[63],并且在FastReport链接的事件处理过程是一个字符串(包含它的名字)。这个不像Delphi中的TNotifyEvent 类型,它是一个方法的地址。

原文地址:https://www.cnblogs.com/moon25/p/5530823.html