请各位大侠看看这个问题,谢谢!(0分)

A

awfigsk

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Caption:='abcd';
if Sender=Button1 then
(Sender as TButton).Caption:='abcdef';
end;
end.
请问Sender就是Button1吗?为什么可以直接写成Sender=Button1,这两个都是常量吗?
Sender本身不就是Tobject吗?为什么还要将它转换成TButton?
 
1)sender 是一个Tobject 的实例
button1 是Tbutton 的实例
tbutton 是从Tobject 继承下来的,所以可以直接sender=button1
2)Tobject 没有caption 属性啊!
 
接受答案了.
 
顶部