C
coleman
Unregistered / Unconfirmed
GUEST, unregistred user!
这是我做试验用的一段代码,请各位高手分析一下,会不会出现异常。
一天后告诉大家答案。(多做几层嵌套是为了实验button1的onclick先返回
,还是button1先free),大家遇到这种问题有没有更好的解决办法。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
procedure proc(var Msg:TMessage)
message wm_user+1;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.proc(var Msg: TMessage);
begin
button1.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Self.Handle,WM_user+1,0,0);
Button2Click(self);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('2');
Button3Click(Self);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage('3');
Button4Click(Self);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage('4');
end;
end.
一天后告诉大家答案。(多做几层嵌套是为了实验button1的onclick先返回
,还是button1先free),大家遇到这种问题有没有更好的解决办法。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
procedure proc(var Msg:TMessage)
message wm_user+1;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.proc(var Msg: TMessage);
begin
button1.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Self.Handle,WM_user+1,0,0);
Button2Click(self);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('2');
Button3Click(Self);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage('3');
Button4Click(Self);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage('4');
end;
end.