Som*_*One 10 delphi multithreading
我有另一个问题!请看这个例子:
// There is a class with some method:
type
TMyClass = class
public
procedure Proc1;
end;
// There is a some thread class:
TMyThread = class(TThread)
protected
procedure Execute; override;
end;
procedure TMyClass.Proc1;
begin
// this method is just calling another thread:
with TMyThread.Create(True) do
begin
FreeOnTerminate := True;
Resume;
end;
// + there are some more actions
end;
procedure TMyThread.Execute;
begin
// in this example this thread just throws exception:
raise Exception.Create('Some exception');
end;
Run Code Online (Sandbox Code Playgroud)
所有我想要的 - 是在TMyClass.Proc1中引发异常并将其抛出如下:
var
myObject: TMyClass;
begin
myObject := TMyClass.Create;
try
myObject.Proc1; // launch and watch what happenings
except
on E: Exception do
WriteErrorLog(E.Message);
end;
FreeAndNil(myObject);
end;
Run Code Online (Sandbox Code Playgroud)
请告诉我如何制作这样的东西?非常感谢!
哦!还有一件事 - 我在Delphi 5上进行编码,所以我没有TThread的"FatalException"属性或类似的东西..
Rem*_*mko 20
你可以使用AcquireExceptionObject():
AcquireExceptionObject返回指向当前异常对象的指针,并防止在当前异常处理程序退出时释放异常对象.
然后你可以将指针发送到另一个线程,如果你在那里提升它将为你释放,否则你必须打电话ReleaseExceptionObject()来释放它.