V
Vision
Unregistered / Unconfirmed
GUEST, unregistred user!
unit myThreadUnit;
interface
uses
Windows, Forms, Controls, SysUtils, Classes, Messages;
type
TmyForm = class;
TmyThread = class(TThread)
private
myForm: TmyForm;
protected
procedure Execute;
override;
procedure CreatemyForm;
public
constructor Create();
destructor Destroy;
override;
end;
TmyForm = class(TForm)
{ ... }
private
{ ... }
public
constructor Create();
destructor Destroy;
override;
end;
implementation
{ TmyForm }
constructor TmyForm.Create();
begin
Inherited Create(nil);
end;
destructor TmyForm.Destroy;
begin
Inherited Destroy;
end;
{ TmyThread }
procedure TmyThread.CreatemyForm;
begin
if myForm=nil then
try
myForm:=TmyForm.Create();
//--->每次执行到这行出错
myForm.Visible:=True;
myForm.BorderIcons:=[biSystemMenu,biMinimize];
myForm.Top:=0;
myForm.Left:=0;
myForm.Width:=100;
myForm.Height:=100;
except
Application.MessageBox('出错了','错误');
end;
end;
procedure TmyThread.Execute;
begin
while not Terminateddo
begin
if myForm=nil then
Synchronize(CreatemyForm);
{ 其它代码略... }
Sleep(100);
end;
end;
constructor TmyThread.Create();
begin
Inherited Create(True);
FreeOnTerminate:=False;
Suspended:=False;
end;
destructor TmyThread.Destroy;
begin
Inherited Destroy;
end;
end.
interface
uses
Windows, Forms, Controls, SysUtils, Classes, Messages;
type
TmyForm = class;
TmyThread = class(TThread)
private
myForm: TmyForm;
protected
procedure Execute;
override;
procedure CreatemyForm;
public
constructor Create();
destructor Destroy;
override;
end;
TmyForm = class(TForm)
{ ... }
private
{ ... }
public
constructor Create();
destructor Destroy;
override;
end;
implementation
{ TmyForm }
constructor TmyForm.Create();
begin
Inherited Create(nil);
end;
destructor TmyForm.Destroy;
begin
Inherited Destroy;
end;
{ TmyThread }
procedure TmyThread.CreatemyForm;
begin
if myForm=nil then
try
myForm:=TmyForm.Create();
//--->每次执行到这行出错
myForm.Visible:=True;
myForm.BorderIcons:=[biSystemMenu,biMinimize];
myForm.Top:=0;
myForm.Left:=0;
myForm.Width:=100;
myForm.Height:=100;
except
Application.MessageBox('出错了','错误');
end;
end;
procedure TmyThread.Execute;
begin
while not Terminateddo
begin
if myForm=nil then
Synchronize(CreatemyForm);
{ 其它代码略... }
Sleep(100);
end;
end;
constructor TmyThread.Create();
begin
Inherited Create(True);
FreeOnTerminate:=False;
Suspended:=False;
end;
destructor TmyThread.Destroy;
begin
Inherited Destroy;
end;
end.