D
DF7C3
Unregistered / Unconfirmed
GUEST, unregistred user!
{
TMyThread是我自定义的一个线程类,代码如下所示。
但是释放的时候,FreeAndNil(FForm2)完全正常,FreeAndNil(FForm1)就报错: error code 5,
请问是怎么回事?
}
TMyThread= class(TThread)
private
FForm1: TMyForm;
FForm2: TForm;
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy;
override;
property Form1: TMyForm read FForm1: //TMyForm 是我自定义的一个窗体
property Form2: TForm read FForm2:
end;
////////////////////////////////////////////////
constructor TMyThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FForm1 := TMyForm.Create;(nil);
FForm2 := TForm.Create(nil);
FreeOnTerminate := True;
end;
destructor TMyThread.Destroy;
begin
FreeAndNil(FForm2);
//执行正常
FreeAndNil(FForm1);
//执行时报错: error code 5
inherited;
end;
procedure TMythread.Execute;
begin
//这里面的代码与Form1和Form2毫无关系
end;
TMyThread是我自定义的一个线程类,代码如下所示。
但是释放的时候,FreeAndNil(FForm2)完全正常,FreeAndNil(FForm1)就报错: error code 5,
请问是怎么回事?
}
TMyThread= class(TThread)
private
FForm1: TMyForm;
FForm2: TForm;
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean);
destructor Destroy;
override;
property Form1: TMyForm read FForm1: //TMyForm 是我自定义的一个窗体
property Form2: TForm read FForm2:
end;
////////////////////////////////////////////////
constructor TMyThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FForm1 := TMyForm.Create;(nil);
FForm2 := TForm.Create(nil);
FreeOnTerminate := True;
end;
destructor TMyThread.Destroy;
begin
FreeAndNil(FForm2);
//执行正常
FreeAndNil(FForm1);
//执行时报错: error code 5
inherited;
end;
procedure TMythread.Execute;
begin
//这里面的代码与Form1和Form2毫无关系
end;