简体   繁体   English

Delphi - DLL中的表单 - 提示未显示

[英]Delphi - Form in DLL - Hints not showing

I have a Delphi form inside a DLL (I know that this restricts the use of the DLL to Delphi but this is not a problem in this case). 我在DLL中有一个Delphi表单(我知道这限制了DLL对Delphi的使用,但在这种情况下这不是问题)。

The DLL exports a function ShowForm that looks roughly like this: DLL导出一个看起来大致如下的函数ShowForm

procedure ShowForm (App : TApplication);
begin
  OldApp := Application;
  try
    Application := App;
    MyForm := TMyForm.Create (nil);
    try
      MyForm.ShowModal;
    finally
      FreeAndNil (MyForm);
    end;
  finally
    Application := OldApp;
  end;
end;

Now on the form I use a TAdvOfficeHint (from the TMS component pack). 现在在表单上我使用TAdvOfficeHint (来自TMS组件包)。 Unfortunately the hints do not show up. 不幸的是,这些提示没有显示出来。

Am I missing something here? 我在这里错过了什么吗? How can I make the form behave exactly as it would if I showed it from the main application? 如何使表单的行为完全像我从主应用程序中显示的那样?

Thanks! 谢谢!

I don't know TAdvOfficeHint but I guess it hooks Application.OnShowHint to set its own THintWindowClass , and even if both the main executable and the DLL are linking in the TMS unit, they each have their own copy of the class which is where things go wrong. 我不知道TAdvOfficeHint但我想它挂钩Application.OnShowHint来设置自己的THintWindowClass ,即使主要的可执行文件和DLL都在TMS单元中链接,它们每个都有自己的类副本,这就是东西出问题。

Assigning Application is not enough: there are other global variables, like Screen , Mouse , etc. Others are even hidden in the implementation so I'd say your chances to make the form behave exactly as from the main application are slim. 分配Application是不够的:还有其他全局变量,如ScreenMouse等。其他甚至隐藏在实现中,所以我说你有机会使表单的行为与主应用程序完全相同

Wrong setting of Application. 应用程序设置错误。

Try this and see if it solves your problem: 试试这个,看看它是否解决了你的问题:

procedure ShowForm (AppHandle : THandle);
begin
  OldAppHandle := Application.Handle;
  try
    Application.Handle := AppHandle;
    ........
  finally
    Application.Handle := OldAppHandle;
  end;
end;

Just found the reason why it does not work. 刚刚找到它不起作用的原因。 As TOndrej states, TAdvOfficeHint hooks Application.OnShowHint and internally executes the following line of code: 正如TOndrej所述, TAdvOfficeHint挂钩Application.OnShowHint并在内部执行以下代码行:

FHintInfo.Assign (AHintInfo);

Assign internally uses a dynamic type check 内部Assign使用动态类型检查

if (Source is TAddvHintInfo) then ...

which fails due to the separate type registries of the DLL and the main application. 由于DLL和主应用程序的单独类型注册表而失败。

I have run into this problem a few times now and maybe I really have to switch to runtime packages to avoid all this stuff. 我现在遇到过这个问题几次,也许我真的必须切换到运行时包以避免所有这些。

Anyway, if there's anything I can do to prevent this, please comment. 无论如何,如果有任何我可以采取的措施来防止这种情况,请发表评论。

我想在Delphi 2006及更高版本中,您可以在EXE代码中调用System.ShareMemoryManager方法,以便其内存管理器与进程内存空间中加载的其他模块共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM