unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject); begin ShowMessage('Button2Click'); end;procedure TForm1.Button1Click(Sender: TObject); begin Button2Click(nil); end;end.
procedure TForm1.Button1Click(Sender: TObject); begin Showmessage('button1 procedure'); end;procedure TForm1.Button2Click(Sender: TObject); begin Button1.Click; end;
button1过程,bttton2调用 这样写:在button2的onclick事件里边button1.onclick(sender); 其实最好是用sender参数自动判断事件触发的是什么控件if sender is button1 then if sender if button2 then with (sender as Tbutton2) do ....
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('Button2Click');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Button2Click(nil);
end;end.
begin
Showmessage('button1 procedure');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Button1.Click;
end;
这样写:在button2的onclick事件里边button1.onclick(sender);
其实最好是用sender参数自动判断事件触发的是什么控件if sender is button1 then
if sender if button2 then with (sender as Tbutton2) do ....
正解!!