程序在事件的循环中,未何无法结束程序,该如何解决
程序在事件的循环中,未何无法结束程序
procedure TForm1.Button1Click(Sender: TObject);
var Inti :integer;
begin
Inti := 1;
repeat
if InternetCheckConnection( 'http://zicheng.oicp.net/bbsxp ', 1, 0) then
begin
edit1.text:= 'Connected ';
Inti:=Inti+1;
Label1.Caption:=IntToStr(Inti);
ProgressBar1.Position:=Inti;
Application.ProcessMessages( ); {这里定义了处理消息,但就是点叉,不让关闭窗口
end
else
begin
edit1.text:= 'Disconnected ';
Inti:=0;
end;
until Inti <=0;
end;
------解决方案--------------------
在窗体类中增加一个Boolean类型变量来标记窗体被关闭
type
TForm1 = class(TForm)
......
private
bFormClosed : Boolean;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bFormClosed := False;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
bFormClosed := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Inti :integer;
begin
Inti := 1;
repeat
if InternetCheckConnection( 'http://zicheng.oicp.net/bbsxp ', 1, 0) then
begin
edit1.text := 'Connected ';
Inti := Inti+1;
Label1.Caption := IntToStr(Inti);
ProgressBar1.Position := Inti;
Application.ProcessMessages( ); {这里定义了处理消息,但就是点叉,不让关闭窗口
end
else begin
edit1.text := 'Disconnected ';
Inti := 0;
end;
until bFormClosed or (Inti <= 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var Inti :integer;
begin
Inti := 1;
repeat
if InternetCheckConnection( 'http://zicheng.oicp.net/bbsxp ', 1, 0) then
begin
edit1.text:= 'Connected ';
Inti:=Inti+1;
Label1.Caption:=IntToStr(Inti);
ProgressBar1.Position:=Inti;
Application.ProcessMessages( ); {这里定义了处理消息,但就是点叉,不让关闭窗口
end
else
begin
edit1.text:= 'Disconnected ';
Inti:=0;
end;
until Inti <=0;
end;
------解决方案--------------------
在窗体类中增加一个Boolean类型变量来标记窗体被关闭
type
TForm1 = class(TForm)
......
private
bFormClosed : Boolean;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bFormClosed := False;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
bFormClosed := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Inti :integer;
begin
Inti := 1;
repeat
if InternetCheckConnection( 'http://zicheng.oicp.net/bbsxp ', 1, 0) then
begin
edit1.text := 'Connected ';
Inti := Inti+1;
Label1.Caption := IntToStr(Inti);
ProgressBar1.Position := Inti;
Application.ProcessMessages( ); {这里定义了处理消息,但就是点叉,不让关闭窗口
end
else begin
edit1.text := 'Disconnected ';
Inti := 0;
end;
until bFormClosed or (Inti <= 0);
end;