高分,<delphi7完美经典>例子的疑惑,问题与代码如下
一个form,两个button点击button1,弹出“button1”,我能理解点击button2,还弹出“button1”,我不能理解,我认为应该什么都不弹出,求解释...
一个form,两个button
点击button1,弹出“button1”,我能理解
点击button2,还弹出“button1”,我不能理解,我认为应该什么都不弹出,求解释
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('Button1');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.OnClick:=Button1Click;
end;
end.
搞明白了,原来早绑定的事件在delphi的dfm文件中
object Form1: TForm1
Left = 510
Top = 232
Width = 168
Height = 168
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 28
Top = 30
Width = 100
Height = 25
Caption = #25353#37397#19968
TabOrder = 0
end
object Button2: TButton
Left = 28
Top = 70
Width = 100
Height = 25
Caption = #25353#37397#20108
TabOrder = 1
OnClick = Button1Click //就是这里
end
end
而且默认的Button1.OnClick=Button1Click并不是绝对的,Button1只是一个方法名,默认是设置相应Button1.OnClick,但也可以相应其他组件的事件 展开
点击button1,弹出“button1”,我能理解
点击button2,还弹出“button1”,我不能理解,我认为应该什么都不弹出,求解释
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('Button1');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.OnClick:=Button1Click;
end;
end.
搞明白了,原来早绑定的事件在delphi的dfm文件中
object Form1: TForm1
Left = 510
Top = 232
Width = 168
Height = 168
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 28
Top = 30
Width = 100
Height = 25
Caption = #25353#37397#19968
TabOrder = 0
end
object Button2: TButton
Left = 28
Top = 70
Width = 100
Height = 25
Caption = #25353#37397#20108
TabOrder = 1
OnClick = Button1Click //就是这里
end
end
而且默认的Button1.OnClick=Button1Click并不是绝对的,Button1只是一个方法名,默认是设置相应Button1.OnClick,但也可以相应其他组件的事件 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询