unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
myPostEvent,FmyEvent: TNotifyEvent;
procedure UserDeclare(sender: TObject);
public
{ Public declarations }
property myEvent: TNotifyEvent read FmyEvent write FmyEvent ;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses unit2;
procedure TForm1.UserDeclare(sender: TObject);
begin
ShowMessage('OK'); //这里是用户自定事件的实现代码
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Form2.ShowModal;
if Assigned(FmyEvent) then
begin
FmyEvent(nil);
myPostEvent := FmyEvent;//这里是保存原来的事件指针
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
FmyEvent := UserDeclare; // 这里是赋用户自定义的事件指针
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
FmyEvent := nil;//屏蔽事件!
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
FmyEvent := myPostEvent; //恢复事件指针
end;
end.
看看这里应该会做了吧!