苍
苍鹰
Unregistered / Unconfirmed
GUEST, unregistred user!
在线程中创建TTimer 控件 在其时间响应程序中要访问VCL资源,在释放该实例时出错
线程程序如下,请问应该如何编写才完全正确。
unit Unit2;
interface
uses
Classes,windows,extctrls,Forms,SysUtils;
type
TFlash = class(TThread)
private
Time : TTimer;
Old: Integer;
I: Integer;
{ Private declarations }
protected
procedure Execute;
override;
Procedure FOnTimer(Sender: TObject);
procedure Start;
public
Constructor Create(spy: Integer);
end;
implementation
uses Unit1;
constructor TFlash.Create(spy: Integer);
begin
inherited Create(false);
Time := TTimer.Create(Application);
Time.Interval := spy ;
Time.OnTimer := FOnTimer;
Old := GetTickCount;
I := 1;
Time.Enabled := false;
end;
procedure TFlash.Execute;
begin
{ Place thread code here }
FreeOnTerminate := True;
if Terminated then
exit;
start;
end;
procedure TFlash.FOnTimer(Sender: TObject);
begin
form1.Edit1.Text := inttostr(GetTickCount - Old) ;
if GetTickCount - Old > 10000 then
begin
form1.Label1.Visible := True;
Time.Enabled := false;
if Assigned(Time) then
Time.Free;
end
else
begin
form1.label1.Visible :=odd(i);
I := I+1;
end;
end;
procedure TFlash.Start;
begin
time.Enabled := true;
end;
end.
线程程序如下,请问应该如何编写才完全正确。
unit Unit2;
interface
uses
Classes,windows,extctrls,Forms,SysUtils;
type
TFlash = class(TThread)
private
Time : TTimer;
Old: Integer;
I: Integer;
{ Private declarations }
protected
procedure Execute;
override;
Procedure FOnTimer(Sender: TObject);
procedure Start;
public
Constructor Create(spy: Integer);
end;
implementation
uses Unit1;
constructor TFlash.Create(spy: Integer);
begin
inherited Create(false);
Time := TTimer.Create(Application);
Time.Interval := spy ;
Time.OnTimer := FOnTimer;
Old := GetTickCount;
I := 1;
Time.Enabled := false;
end;
procedure TFlash.Execute;
begin
{ Place thread code here }
FreeOnTerminate := True;
if Terminated then
exit;
start;
end;
procedure TFlash.FOnTimer(Sender: TObject);
begin
form1.Edit1.Text := inttostr(GetTickCount - Old) ;
if GetTickCount - Old > 10000 then
begin
form1.Label1.Visible := True;
Time.Enabled := false;
if Assigned(Time) then
Time.Free;
end
else
begin
form1.label1.Visible :=odd(i);
I := I+1;
end;
end;
procedure TFlash.Start;
begin
time.Enabled := true;
end;
end.