Link to home
Start Free TrialLog in
Avatar of djadja
djadja

asked on

How do I make a form I have in a DLL behave as if its part of the application?

My application calls a DLL function that in turn shows a form contained inside the DLL, eg.

application (form1)
DLL_Function_ShowForm(Application);

dll: DLL_Function_ShowForm(oApplication: TApplication);
with TfrmMessage.Create(nil) do begin
try
  Label1.Caption:=oApplication.ExeName;
  ShowModal;
finally
  Free;
end;

3 things wrong:
1. the form is shown as an extra 'program' on the taskbar and I don't want it to be...
2. If I obscure the application window and then use the taskbar button to re-activate it, it doesn't bring the message form to the top
3. If I obscure the message form and use the taskbar button to re-activate it, it doesn't bring the application's form up behind it.

I use the borlndmm.dll to pass objects and as you can see, I also pass the application object, I've tried "with TfrmMessage.Create(oApplication) do begin" but that doesnt work and it gives me an AV on exit.

Any ideas anyone?
Avatar of VSF
VSF
Flag of Brazil image

Listenning...
Avatar of geobul
geobul

Hi,
try this:
in DLL:

function ShowDllForm1(AHandle: THandle; modal: boolean):LongInt;
begin
 Application.Handle := AHandle;
 if DllForm1 = nil then
   DllForm1 := TDllForm1.Create(Application);
 Result := LongInt(DllForm1);
 if modal then DllForm1.ShowModal
 else          DllForm1.Show;
end;

exports ShowDllForm1;

in app:

function ShowDllForm1(AHandle: THandle; modal: boolean):LongInt; external 'DllForm.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
  DllForm : LongInt;
begin
  DllForm := ShowDllForm1(Application.Handle, false);
end;

Regards, Geo
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot - will try it tonight...
Avatar of djadja

ASKER

Fantastic - solved all 3 issues with such a -=SIMPLE=- line of code (duh!) - given you an extra 50!

Cheers
Thanks a lot. Very nice of you.
Regards, Geo