一个例子:
unit Unit1;
interface
uses
Windows, SysUtils, Classes;
type
//定义事件类型
TMyEvent = procedure (op: string; var d: double) of object;
TMyClass = class
private
FMyEvent: TMyEvent;
public
//定义事件
property MyEvent: TMyEvent read FMyEvent write FMyEvent;
procedure Calc;
end;
implementation
procedure TMyClass.Calc;
var
s: string;
d: double;
begin
//....
if Assigned(FMyEvent) then FMyEvent(s, d); //触发事件
//....
end;
end.