procedure onObjectClick(Sender:TObject);
begin
if Sender is TButton then
begin
showmessage('button');
....
end
else if Sender is TForm then
begin
showmessage('form');
....
end
.....
end;
你可以自定义函数或过程中传sender的,比如:
procedure myfunc(sender : tobject);
begin
if sender is tbutton then
begin
.....
showmessage('sender is button');
end
else
begin
......
end;
end;
是不是可以把Sender理解为当前活动的对象呢?
上面举的例子:
procedure onObjectClick(Sender:TObject);
begin
if Sender is TButton then
begin
showmessage('button');
....
end
else if Sender is TForm then
begin
showmessage('form');
....
end
.....
end;
都是用的Button,Form这样的组件。可不可以用自定义的对象呢?
比如写if Sender is MyObj then ......