delphi - Delphi 5中的ApplicationHandleException变量?

标签 delphi delphi-5

我正在尝试使用 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/

相关文章:

delphi - TRadioGroup 具有可包装的项目

delphi - TListView 标题列中的复选框 - 如何防止它窃取焦点?

delphi - 为什么在Delphi中调用函数时不用逗号分隔参数?

delphi - 使用 Chromium Embedded 时如何修复此内存泄漏?

delphi - 本地网络上 ftp 的替代方案

delphi - 如何将我发布的属性放入Object Inspector的指定类别中?

delphi - 应用程序 (TApplication) 实例在何时何地创建?

delphi - 如何给Delphi窗体添加背景图片

delphi - 如何在执行时连接 Firebird 数据库?

delphi - Delphi 5 有排序字典容器吗?