谁帮我看看这个线程的问题在哪?
unit UTimeDisplay;
interface
uses
Classes, Graphics, ExtCtrls,Controls,SysUtils,Dialogs,StdCtrls;
type
TCurrTimeDisplay= Class(TThread)
Private
aTimer:TTimer;
aLabel:TLabel;
protected
procedure Execute; override;
procedure DoTerminate;override;
Public
Constructor Create(var TmShowLbl:TLabel);
procedure TimerTimer(Sender:TObject);
end;
implementation
Constructor TCurrTimeDisplay.Create(Var TmShowLbl:TLabel);
begin
//Priority:=tpHigher;
FreeOnTerminate:=True;
aLabel:=TmShowLbl;
aTimer:=TTimer.Create(nil);
with aTimer do
begin
Interval:=1000;
OnTimer:=TimerTimer;
end;
inherited Create(False);
end;
Procedure TCurrTimeDisplay.Execute;
begin
TimerTimer(aTimer);
end;
procedure TCurrTimeDisplay.TimerTimer(Sender:TObject);
begin
aLabel.Caption:=TimeToStr(Time);
aLabel.Refresh;
aTimer.Enabled:=True;
end;
Procedure TCurrTimeDisplay.DoTerminate;
begin
if aTimer<>nil then
aTimer.Free;
end;
现在问题是使用这个线层的程序 只要lose focus(鼠标点到程序外面)就出现“read voliation 0×00000...”错误
怎么控制线程的结束 我不会。
同时还有个问题,我这样写主线层上的赋给“Var TmShowLbl:TLabel”的label 并不会一秒一秒变化 而是就第一次执行的时间 :(