You must follow the OS way of ordering the windows (with the use of a handle). A DLL's application handle is zero by default, so you need to define it when showing modal dialogs.
According to documentation Vcl.Forms.TApplication.Handle
:
Note: When writing a DLL that uses VCL forms, assign the window handle of the host EXE's main window to the Handle property of the DLL's global Application variable. This makes the DLL's form part of the host application. Never assign to the Handle property in an EXE.
To maintain the Z-order of the dll modal forms, do as Peter Below suggests
:
// In the dll
var
oldWnd: HWND;
begin
oldWnd := Application.Handle;
Application.Handle := HandleOfHostform; // <-- Pass the exe host form handle
try
.... create and show the DLL form
finally
Application.Handle := oldWnd;
end;
end;
The modal form should be created without an owner, TMyDllForm.Create(nil)
.
I'm not 100% sure Delphi-7 correctly resolves the handle in a DLL this way.
Another approach would be to override CreateParams
for the form object, as suggested here
.
procedure TMyDLLForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.WndParent := HandleOfHostForm;
end;