....... ( 积分: 50 )

  • 主题发起人 主题发起人 bnbchinafbi
  • 开始时间 开始时间
B

bnbchinafbi

Unregistered / Unconfirmed
GUEST, unregistred user!
问题1: procedure Button1Click(Sender: TObject);中的Sender参数有什么用?
问题2: 单击 Button1后,为什么Button1会消失?
问题3: myobj的类型为什么是TButton?
请看下面的程序:
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;
Tmyobj=class
procedure MyobjOne;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ Tmyobj }

procedure Tmyobj.MyobjOne;
begin
showmessage('MyobjOne');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
myobj:Tmyobj;
begin
myobj.Create ;
myobj.MyobjOne ;
myobj.Free ;
end;

end.
 
问题1: procedure Button1Click(Sender: TObject);中的Sender参数有什么用?
问题2: 单击 Button1后,为什么Button1会消失?
问题3: myobj的类型为什么是TButton?
请看下面的程序:
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;
Tmyobj=class
procedure MyobjOne;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ Tmyobj }

procedure Tmyobj.MyobjOne;
begin
showmessage('MyobjOne');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
myobj:Tmyobj;
begin
myobj.Create ;
myobj.MyobjOne ;
myobj.Free ;
end;

end.
 
myobj:=Tmyobj.create;
 
procedure TForm1.Button1Click(Sender: TObject);
var
myobj:Tmyobj;
begin
myobj:=Tmyobj.Create;
myobj.MyobjOne ;
myobj.Free ;
end;
 
1、
In an event handler, the Sender parameter indicates which component received the event and therefore called the handler. Sometimes it is useful to have several components share an event handler that behaves differently depending on which component calls it. You can do this by using the Sender parameter in an if...then...else statement. For example, the following code displays the title of the application in the caption of a dialog box only if the OnClick event was received by Button1.

procedure TMainForm.Button1Click(Sender: TObject);
begin
if Sender = Button1 then
AboutBox.Caption := 'About ' + Application.Title
else
AboutBox.Caption := '';
AboutBox.ShowModal;
end;

2、
procedure TForm1.Button1Click(Sender: TObject);
var
myobj :Tmyobj;
begin
myobj := Tmyobj.Create ;
myobj.MyobjOne ;
myobj.Free ;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
myobj:Tmyobj;
begin
myobj.Create;
myobj.MyobjOne ;
ShowMessage(TButton(myobj).Name);
myobj.Free ;
end;

楼主的程序 我这样改了一下 结果显示为TButton1
这里面隐藏的了什么东西
 
to Avalon
我所说的Button1消失是指Button1这个按纽在Form1窗体中看不见了。
 
没人,高手改行了吗?
 
晕倒,加我的QQ吧,那样子聊比较快,这么发,要到何时才能完
453876005
对了,记得注明清楚,不随便加人的~
 
是否,button1的visible为false?
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
686
import
I
I
回复
0
查看
763
import
I
I
回复
0
查看
673
import
I
I
回复
0
查看
740
import
I
后退
顶部