编译系统是怎么区分我单击是button1还是button2,在线等候?(50分)

H

hthugm

Unregistered / Unconfirmed
GUEST, unregistred user!
Tnotify=procedure Tbutton_onClick(sender:TObject) of TObject
中的Sender是传进去还是返回的?如果是传进去,是怎么传的
讲简单点就是我有有两个按钮OnClic事件,编译系统是怎么区分我单击是button1还是
button2,因为在类中它是这样调用的
if AsSigned(FOnClick) then
FOnClick(Sender) //它在这里是怎么区分button1和button2
的,ID号好象没有传进去,而且Sender是属于TObject而不是TButton
 
IF TButton(Sender)=Button1 then
...
IF TButton(Sender)=Button2 then
...
[:)][:)][:)][:)]
 
是这么调用的:
procedure TControl.Click;
begin
{ Call OnClick if assigned and not equal to associated action's OnExecute.
If associated action's OnExecute assigned then
call it, otherwise, call
OnClick. }
if Assigned(FOnClick) and (Action <> nil) and (@FOnClick <> @Action.OnExecute) then
FOnClick(Self)
else
if not (csDesigning in ComponentState) and (ActionLink <> nil) then
ActionLink.Execute(Self)
else
if Assigned(FOnClick) then
FOnClick(Self);
end;
可见传进去的参数是Self,也就是被点击的对象。
 
to xeen:
是这么调用的:
procedure TControl.Click;
begin
{ Call OnClick if assigned and not equal to associated action's OnExecute.
If associated action's OnExecute assigned then
call it, otherwise, call
OnClick. }
if Assigned(FOnClick) and (Action <> nil) and (@FOnClick <> @Action.OnExecute) then
FOnClick(Self)
else
if not (csDesigning in ComponentState) and (ActionLink <> nil) then
ActionLink.Execute(Self)
else
if Assigned(FOnClick) then
FOnClick(Self);
end;

这一段代码也没有根据ID号来判断的,它只是相当于C++的基类的指针指向派生类对象
的引用罢了。编译系统生成代码时加了什么进去,C++的编译是加了THIS这个参数进去
才知道调用的究竟是哪个函数。希望继续指教。
 
跟C++的this指针类似:
所有类的方法都有个隐含参数,调用方法的时候会把当前对象的指针传进来,就是Self.
 
同意楼上
 
Tbutton(sender).caption
呵呵,学习。共同进步。
 
顶部