教程-Tbutton(sender) 与 (sender as Tbutton) 等价吗?

问题:Tbutton(sender) 与 (sender as Tbutton) 等价吗? 
答: 
1. Sender As TButton时delphi做类型检查。
比如:
var frm:TForm;
beign
  frm:=TFrom.Create(Applicaion);
  (frm as TButton).Caption:='这是错误的';//这里delphi不允许通过
end;
 
2. 而TButton(Sender)不管怎么样总是试图转化的。
比如:
TButton(frm).Caption:='虽然这样可以,但是错误';//这里可以通过,但是如果类型不对,造成内存混乱。
再如:
var i:Longint;
begin
  frm:=TForm.Create(Applicaiton);
  i:=Longint(Frm);
  TForm(i).Caption:='这样写是对的';
end;
原文地址:https://www.cnblogs.com/FKdelphi/p/4654311.html