为什么我的timer在多线程下无法启动(100)

  • 主题发起人 绯红之王
  • 开始时间

绯红之王

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit2;interfaceuses Classes,ExtCtrls,unit1,SysUtils;type sss = class(TThread) procedure xontime(Sender: TObject);
private { Private declarations } timer1 : ttimer;
protected procedure Execute;
override;
end;
implementationprocedure sss.Execute;
begin
form1.Caption := 'sss';
timer1 := ttimer.Create(form1);
timer1.Interval := 1000;
timer1.Enabled := true;
timer1.OnTimer := xontime;
end;
procedure sss.xontime(Sender: TObject);var x : word;
begin
x :=strtoint(form1.Label1.Caption);
inc(x);
form1.Label1.Caption := inttostr(x);
end;
end.
在form1里面create这个线程,timer就是没有反应求解
 
timer的工作需要消息支持在多线程中没有消息泵,所以不能用你在多线程中可以使用系统定时器来实现
 
Timer是基于wm_Timer消息的.也就是说是基于消息机制的.每个线程都有自己的消息队列.所以除非你在线程中建一个消息循环,否则wm_Timer消息的不到处理,你的Timer控件也就不能用了.还有一个方式就是借助多媒体函数的时间回调函数.timeSetEvent.这个函数不是基于消息机制的
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
658
import
I
I
回复
0
查看
511
import
I
S
回复
0
查看
692
SUNSTONE的Delphi笔记
S
I
回复
0
查看
615
import
I
顶部