我正在尝试使用 AsyncCalls
,它假设也适用于 Delphi 5。
如果我注释调用/使用 ApplicationHandleException
的行,一切都会编译并运行良好。 Delphi 5 没有的classes 变量(我也不确定它是什么时候引入的)。
procedure TThreadPool.MainThreadWndProc(var Msg: TMessage); begin try ... except if Assigned(ApplicationHandleException) then ApplicationHandleException(Self); end; end;
我几乎确信在 Delphi 5 中上述应该是:
try
...
except
Application.HandleException(Self);
end;
但不确定如何处理此代码:
destructor TInternalAsyncCall.Destroy; begin ... // TAsyncCall.Destroy either already called Sync() or we are a "forgotten" async call // and we need to handle the exception ourself by trying to throw it in the main thread // or just ignoring it. if FFatalException <> nil then begin if Assigned(ApplicationHandleException) and // <--- (ThreadPool.FMainThreadVclHandle <> 0) and IsWindow(ThreadPool.FMainThreadVclHandle) then PostMessage(ThreadPool.FMainThreadVclHandle, WM_RAISEEXCEPTION, WPARAM(FFatalErrorAddr), LPARAM(FFatalException)) else FFatalException.Free; end; inherited Destroy; end;
Delphi 5 中正确的“翻译”是什么?我应该忽略这个变量,因为它不存在吗?请指教。
最佳答案
在TApplication.Create
中,有一段代码分配给ApplicationHandleException
变量。
if not Assigned(System.Classes.ApplicationHandleException) then
System.Classes.ApplicationHandleException := HandleException;
现在,当您允许隐式 Self
目标时,HandleException
实际上是 Self.HandleException
。
所以是的,您可以替换:
if Assigned(ApplicationHandleException) then
ApplicationHandleException(Self);
与
if Assigned(Application) then
Application.HandleException(Self);
一般来说,对于 Delphi 5,您将替换
Assigned(ApplicationHandleException)
与
Assigned(Application)
Assigned(Application)
的计算结果几乎总是为 True
,但您可能正在非 VCL 设置中工作,或者代码可能在之前执行全局 Application
对象创建后或销毁后。
关于delphi - Delphi 5中的ApplicationHandleException变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43186758/