We help IT Professionals succeed at work.

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

djadja
djadja asked
on
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?
Comment
Watch Question

VSF

Commented:
Listenning...
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT
Commented:
Using your code it is:

application (form1)
DLL_Function_ShowForm(Application.Handle);

dll:
function DLL_Function_ShowForm(oApplication: THandle): LongInt; stdcall;
begin
  Application.Handle := oApplication;
  with TfrmMessage.Create(Application) do begin
    try
      Label1.Caption:=Application.ExeName;
      ShowModal;
    finally
      Free;
    end;
  end;
end;

Regards, Geo
Thanks a lot - will try it tonight...

Author

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

Cheers
CERTIFIED EXPERT

Commented:
Thanks a lot. Very nice of you.
Regards, Geo

Explore More ContentExplore courses, solutions, and other research materials related to this topic.