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).
The DLL exports a function ShowForm
that looks roughly like this:
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). 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 hooksApplication.OnShowHint
to set its ownTHintWindowClass
, 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.Assigning
Application
is not enough: there are other global variables, likeScreen
,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.I guess in Delphi 2006 and later versions you can call System.ShareMemoryManager method in the EXE code, so that its memory manager is shared with other modules loaded in the process memory space.
Wrong setting of Application.
Try this and see if it solves your problem:
Just found the reason why it does not work. As TOndrej states,
TAdvOfficeHint
hooksApplication.OnShowHint
and internally executes the following line of code:Assign
internally uses a dynamic type checkwhich fails due to the separate type registries of the DLL and the main application.
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.