关于Delphi中的application.ProcessMessages问题(处理事件)
━━━━━━━━━━━━━━━━━━━━━━━━━━
很多资料中提到,Delphi中的application.ProcessMessages相当于VB中的Doevents函数(转让进程控制),可是,在实际应用中,却不是这么回事。例:
(VB Code)
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Text1.Text = 0
For i = 1 To 10000
For j = 1 To 10000
DoEvents
Text1.Text = Val(Text1.Text) + 1
Next
Next
End Sub
Private Sub Command2_Click()
MsgBox 1
Unload Me
End Sub
=================================================================
(Delphi Code)
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
edit2.Text:='0';
for i:=1 to 10000 do
Begin
for j:=1 to 10000 do
Begin
application.ProcessMessages;
edit1.Text:=inttostr(strtoint(edit2.text)+ 1);
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('1');
Close;
end;
=================================
当点击VB中的Command2按钮时,马上弹出消息框并关掉应用程序(或点窗体关闭键时会即时关掉程序),可是,点Delphi中的Button2Click时,虽然也弹出消息框,可是应用程序并不关闭,仍在计算,即使点窗体关闭键也要计算完后才关掉。在一些情况下,可能要用到大循环,因此,要给用户提供随时中止程序的功能,那么,在Delphi中,如何才能实现?
━━━━━━━━━━━━━━━━━━━━━━━━━━
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('1');
Application.Terminate; //改为这个。
end;
━━━━━━━━━━━━━━━━━━━━━━━━━━
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
edit2.Text:='0';
for i:=1 to 10000 do
Begin
for j:=1 to 10000 do
Begin
application.ProcessMessages;
if Application.Terminated then Exit;
edit1.Text:=inttostr(strtoint(edit2.text)+ 1);
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('1');
Application.Terminate;
end;
分享到:
相关推荐
Application.ProcessMessages作用Application.ProcessMessages作用Application.ProcessMessages作用Application.ProcessMessages作用
Application.ProcessMessages; begin for i:=0 to j do begin form1.Label1.Caption:='正在读取第 '+inttostr(i)+' 包 '; form1.Memo1.Text:=form1.Memo1.Text+ midstr(strtohex(form1.Memo2.text),2048*i,...
Delphi WebBrowser 将一段HTML文字显示在网页浏览器中,实际是创建了一个HTML格式内容并显示出来,主要使用Delphi中内置的WebBrowser方法来实现: WebBrowser1.Navigate('about:blank'); while(tag=0) do ...
Application.ProcessMessages; end; tsList.Add(s); try try ADOQuery.First; While Not ADOQuery.Eof do begin s:=''; for y:=0 to ADOQuery.FieldCount-1 do begin s:=s+ADOQuery.Fields[y].AsString+...
Delphi演示如何将一张图片的颜色加深,类似于调整对比度,不过本效果不加入了渐变加深的动画效果,按住按钮图片一直变暗下去,要知空间,你可看下以下代码: ... //让Application去处理消息队伍中的消息 end;
Delphi 编写的图片垂直交错显示效果,之前就分享过这种效果,类似百叶窗的交替显示效果,可用于图片转场,不过本效果还有很多地方需要优化,当时是写给一本书,作为随书实例的,有兴趣的可参考,关于本功能的关键...
Application.ProcessMessages; end; procedure TFrmProgress.SetProgressMax(const Value: Integer); begin FProgressMax := Value; ProgressBar.Max:=FProgressMax; end; procedure TFrmProgress....
Application.ProcessMessages; SearchFile1(List[I], Edit1.Text); ProgressBar1.Position := I; end; ListBox1.Items.Text := FileNameList.Text; ButtonSearchFile.Caption := IntToStr(FileNamePathList....
TIdAntiFreeze在Indy内部定时中断对栈的调用,并在中断期间调用Application.ProcessMessages方法处理消息,而外部的Indy调用继续保存阻塞状态,就好像TIdAntiFreeze对象不存在一样。你只要在程序中的任意地方添加一...
批量下载QQ邮箱中的所有附件 procedure TFrm_QQMailRev.bt_revClick(Sender:... application.ProcessMessages; end; Label3.Caption := '共接收附件:['+intToStr(fCount)+'] '; IdPOP31.Disconnect; //断开连接 end;
Application.ProcessMessages; end; end; // we must use the result Total := n2; time2 := Now; Label1.Caption := FormatDateTime ( 'n:ss', Time2-Time1) + ' seconds'; end; 记时这段代码值得一看,...
unit TreeViewFunctions; interface uses Windows, Messages, SysUtils, Variants, Classes, ComCtrls, Controls, Forms, FileCtrl, StrUtils, Masks, Vcl.... if Application.MessageBox('确定要删除这个文件夹吗...
Application.ProcessMessages; end; end; // 注释和取消注释 // 获得选中的文本的起始行和结束行 procedure TStringFunction.InsertComment(Memo: TMemo); var str: string; x, y: Integer; begin str := ...
- Added fix for: QC #68493: Switching away and back to Delphi orphans focus on Code Editor 2009-12-05: - Added fix for: Vista compatible main icon resource doesn't work 2009-09-03: - Added fix for:...
Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the ...
Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the entire...
Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the entire...
Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the entire...
Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the ...
So I decided to use the sockets of Delphi 3 founded in D3 c/s D3.01 pro and D3.01 c/s. Now all seems to work fine and much more smooth. And of course the interface of SakEmail hasn‘t changed.26/10/...