F
fan_dph
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:
操作符as是将子类对象转化为父类类型的实例;
如:TA = class
A:integer;
end;
TB = class(TA)
B:integer;
end;
var
A:TA;
B:TB;
(B as TA).A:=100;//ok
(A as TB).B:= 100;
//No
但是:为是么在下面程序中可以?
因为sender 是tobject 的对象;tobject 是Tbutton 的祖先类;
procedure button1.onclick(sender:Tobject);
begin
(sender as TButton).caption:='aaa';
end;
操作符as是将子类对象转化为父类类型的实例;
如:TA = class
A:integer;
end;
TB = class(TA)
B:integer;
end;
var
A:TA;
B:TB;
(B as TA).A:=100;//ok
(A as TB).B:= 100;
//No
但是:为是么在下面程序中可以?
因为sender 是tobject 的对象;tobject 是Tbutton 的祖先类;
procedure button1.onclick(sender:Tobject);
begin
(sender as TButton).caption:='aaa';
end;