for m:= 1 to 100 do
beginss:=Format('%.6d',[m]);
sleep(50);
label1.caption:=ss;end;label1.caption 为什么不能逐一显示啊,只能显示100。请教各位了。
beginss:=Format('%.6d',[m]);
sleep(50);
label1.caption:=ss;end;label1.caption 为什么不能逐一显示啊,只能显示100。请教各位了。
解决方案 »
- 退出程序很难吗?为什么我这么做是不行的,应该怎么做呢?
- 求助!!删除记录问题.
- 与access连接后,怎么也断不开,大家看看
- 请教一个问题,急!!!
- 一个6000000条纪录的dbf文件,在本地,我用程序和其他的关联表格进行操作以后,如何加强效率(内详)
- 谁有写好的DES 和3DES 函数 或DLL ?
- 请问怎么做才可以在子类窗体中看到父类窗口中建立的控件呢?
- 自认为是高手的请进来拿走100分
- 我已经问了第三次了,难道真没有人会???(在VC中这个问题只是两三行代码就可以解决的),Delphi没有VC方便?
- 那有好的控件下啊?
- 在工程文件中写INI文件,代码报错
- 每次运行程序都弹出那个 用户名 和 密码 验证的提示,如何消除啊?~~~~~~~~~~~~~~~~~~~~
但是这个时候你当前的代码片段尚未结束退出,消息泵无法发送lable的caption更新消息的,直到你的代码片段结束,才轮到消息泵发送lable的更新消息,此时当然直接更新最后一个标题文字咯要想达到你的效果,普遍做法是在你的循环代码片段里面,每步发出Application.ProcessMessage,当前代码片段挂起,主动呼叫消息泵处理队列里面的消息,处理完毕再回到你的代码片段,有点类似dos下的中断转移及中断现场的恢复。VCL消息泵循环处理
while 不是WM_QUIT的消息 do
begin
从消息队列捡取一条消息
发送到消息的窗口过程
窗口过程找到这条消息的处理句柄
(也就是你用的什么OnClick,OnTimer,OnShow,OnClose)等等句柄处理
|
|
这个代码片段就是你的循环代码片段,你的代码片段没有结束退出,这个消息泵无法执行下一个while消息处理判断,当然就无法更新lable的caption
end
begin
ss := Format('%.6d', [m]);
sleep(50);
label1.caption := ss;
Application.ProcessMessages;
end;
for m:= 1 to 100 do
beginss:=Format('%.6d',[m]);
sleep(50);
label1.caption:=ss;
application.ProcessMessages;////
end;
application.ProcessMessages;//用了这个还要用yield吗?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1:TForm1;
i:integer;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
Inc(i);
if i>100 then i:=1;
label1.caption:=IntToStr(i);
if i=100 then Timer1.Enabled:=False;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if not Timer1.Enabled then
begin
i:=0;
Application.ProcessMessages;
Timer1.Interval:=100;
Timer1.Enabled:=true;
end;
end;end.
在powerbuilder 中有一個函數yield();用法如下:
for i = 1 to n
yield()
....
....
next
這樣在迴圈過程中及時兼顧系統操作,譬如拷貝檔,各種按鍵等都是可以啟動的。它在Delphi所對應的函數類似於:Application.ProcessMessages;如果你運行一個非常耗時的迴圈,那麼在這個迴圈結束前,你的程式可能不會回應任何事件,你按按鈕沒有反應,程式設置無法繪製表單,看上去就如同死了一樣,這有時不是很方便,例如於終止迴圈的機會都沒有了。這時你就可以在迴圈中加上這麼一句,每次程式運行到這句時,程式就會讓系統回應一下消息,從而使你有機會按按鈕,表單有機會繪製...
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Timer1: TTimer;
ProgressBar1: TProgressBar;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1:TForm1;
i:integer;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
Inc(i);
if i>100 then i:=1;
label1.caption:=IntToStr(i);
ProgressBar1.Position:=ProgressBar1.Position+1;//進度條
if i=100 then Timer1.Enabled:=False;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if not Timer1.Enabled then
begin
i:=0;
ProgressBar1.Min:=0;
ProgressBar1.Max:=100;
Application.ProcessMessages;
Timer1.Interval:=100;
Timer1.Enabled:=true;
end;
end;end.
begin
ss:=Format('%.6d',[m]);
leep(50);
label1.caption:=Format('%.6d',[m]);
label1.Repaint;
end;
begin
application.process//好像是这么写的吧
ss:=Format('%.6d',[m]);
sleep(50);
label1.caption:=ss;end;