L
lynu
Unregistered / Unconfirmed
GUEST, unregistred user!
//经测试,可以在事件发生时得到执行,但访问函数参数多数出错(第一个参数好象正常
uses typinfo,...;
procedure SetEventToProc(Sender:TObject;evenname:string;eointer);
var
m:TMethod;
begin
//将一个vcl对象的事件指向一个普通过程或函数
m.Code:=e;
m.Data:=Sender;
try
SetMethodProp(Sender,evenname,m);
except
end;
end;
//测试代码
procedure CloseQuery(Sender: TObject
var CanClose: Boolean);
begin
ShowMessage(TForm(Sender).Caption);//正确
//CanClose:=true;//访问非法,未知何因
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetEventToProc(Sender,'OnCloseQuery',@CloseQuery);
end;
uses typinfo,...;
procedure SetEventToProc(Sender:TObject;evenname:string;eointer);
var
m:TMethod;
begin
//将一个vcl对象的事件指向一个普通过程或函数
m.Code:=e;
m.Data:=Sender;
try
SetMethodProp(Sender,evenname,m);
except
end;
end;
//测试代码
procedure CloseQuery(Sender: TObject
var CanClose: Boolean);
begin
ShowMessage(TForm(Sender).Caption);//正确
//CanClose:=true;//访问非法,未知何因
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetEventToProc(Sender,'OnCloseQuery',@CloseQuery);
end;