Self是代表窗体,如果本组件呢.
如,一个按钮的单击事件:(当这个按钮的标题为1时,单击后变成2,不是1则单击后为1)
VFP中可以这样表达
If this.caption="1" then this.caption=2 else this.caption:=1
在DELPHI中应该怎样表达
如,一个按钮的单击事件:(当这个按钮的标题为1时,单击后变成2,不是1则单击后为1)
VFP中可以这样表达
If this.caption="1" then this.caption=2 else this.caption:=1
在DELPHI中应该怎样表达
TButton(Sender).Caption='2'
else
TButton(Sender).Caption='1'
如果调用的是其他实例,self就不是窗体。贴段代码,你体会一下:
procedure Tform1.formcreate(sender:Tobject);//代码一
begin
self.color:=clred;
end;
和
procedure Tform1.formcreate(sender:Tobject);//代码二
begin
color:=clred;
end;
窗体一运行就是红色,代码二中之所以不写,是因为代码包含在form中,如果没有特别指明所属对象,系统会自动把它当成form.