当前位置:主页>销售管理软件> 列表

急!!!一个简单问题,第一个解决问题的90分,在线等! 找管家婆软件报价

仓库管理软件版1楼: 先点击Button1,2、3秒后点击Button2,但是两个按钮的标题同时改变,想让他按照自己的延时显示标题。请各位指教。

procedure TimeDelay(DT: DWORD);
var
TT : DWORD;
begin
TT := GetTickCount();
while GetTickCount()-TT
begin
Sleep(10);
Application.ProcessMessages; //
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
button1.Caption:=''0'';
timedelay(5000);
button1.Caption:=''1'';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
button2.Caption:=''0'';
timedelay(10000);
button2.Caption:=''2'';
end;

2楼: 大家帮帮忙吧!!!! 如简单进销存管理软件

3楼: 你运行2个实例
1个实例点button1
1个实例点button2
你就知道结果了

4楼: 其实button1已经运行结束了,但是caption 没有显示出来
直到button2运行结束 所以会同时显示出来啊

5楼: 不明白,能再清楚一些吗,谢谢!

6楼: 对,是最后同时显示出来,怎么才能让1先显示出来。

仓库管理软件版7楼: 你用我的方法做一下就知道了

8楼: 大哥我不知道怎么弄能详细一点吗?

9楼: 有意思,我试验了,是先显示后按的哪个按钮,然后显示先按的哪个按钮。谁能解释一下原因?

10楼: 还有意思,郁闷了一晚上了,哪位高手请赐教!!!

11楼: type
Tabc=class(tthread)
public
button:Tbutton;
dt1:Integer;
procedure Execute; override;
constructor Create(Threadbutton:TButton;dt:Integer);
end;

var
Form1: TForm1;
abc:Tabc;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
abc:=Tabc.Create(button1,5000);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
abc:=Tabc.Create(button2,10000);
end;

{ Tabc }

constructor Tabc.Create(Threadbutton: TButton;dt:Integer);
begin
button:=Threadbutton;
dt1:=dt;
Inherited Create(False);
end;

procedure Tabc.Execute;
var
TT:Integer;
begin
inherited;
button.Caption:=''0'';
TT := GetTickCount();
while GetTickCount()-TT begin
end;
button.Caption:=button.Name;
end;

12楼: 运行application.ProcessMessages
它把消息处理掉了
所以就不能显示caption
到最后application.ProcessMessages结束 才会重新处理消息 如管家婆软件报价

13楼: 所以我用现成做了一个,成功~~

仓库管理软件版14楼: 非常感谢!!!

15楼: 我想你对整个处理的流程有误解。


procedure TForm1.Button1Click(Sender: TObject);
begin
button1.Caption:=''0'';
timedelay(5000); ----------------
button1.Caption:=''1''; <--------| |
end; | |
| |
procedure TimeDelay_1(DT: DWORD); <--|--------|
var |
TT : DWORD; |
begin |
TT := GetTickCount(); |
while GetTickCount()-TT
begin | |
Sleep(10); | |
Application.ProcessMessages; -----|-------------- |
end; | | |
end; ------------------- | |
| |
procedure TForm1.Button2Click(Sender: TObject); <---- |
begin |
button2.Caption:=''0''; |
timedelay(10000); --------------------- |
button2.Caption:=''2''; <-------------- | |
end; ----------|---------|-----
| |
procedure TimeDelay_1(DT: DWORD); <----- | ---------
var |
TT : DWORD; |
begin |
TT := GetTickCount(); |
while GetTickCount()-TT
begin |
Sleep(10); |
Application.ProcessMessages; |
end; |
end; -------------

因此执行顺序是
procedure TForm1.Button1Click(Sender: TObject);
begin
button1.Caption:=''0'';
timedelay(5000);
button1.Caption:=''1'';
end;
然后在timedelay(5000);的某一个Application.ProcessMessages中处理Button2.Click,然后跳转到BUTTON2_CLICK事件处理程序,并且一直到BUTTON2_timedelay完毕BUTTON2的处理之后才返回
button1.Caption:=''0'';
button2.Caption:=''0'';
button2.Caption:=''2'';
button1.Caption:=''1'';
这就是你问题的原因。另外我看不出GetTickCount的必要,这个函数会不停的查询CPU,消耗CPU资源,因此除非必要时最好不要使用的,对于秒级别的间隔,完全没比要用此函数.还有线程,定时器都属于比较稀缺的系统资源,最好能够规划使用.