Board index » delphi » DLL forms shown on a panel

DLL forms shown on a panel

I have a form (F2, that I'd like to show inside a panel (P1) on
another form (F1).
That's no problem - I subclass the form and create it with:

F2 := TMyForm.Create(Application)
F2.Parent := F1.P1;
F2.Show;

However, now I want F2 to reside inside a DLL, so that F1 calls a
function that displays it:

unit F1;
...
procedure F2.DisplayForm;
begin
  ShowF1(P1);
end;

unit F2;
...
procedure ShowF1(AParent : TWinControl);
begin
  F2 := TMyForm.Create(nil)
  try
    F2.Parent := AParent;
    F2.Show;  <----------------------- Terminates immediately
  finally
    F2.Free;
  end;
end;

F2.Show will terminate after showing it. If I try with ShowModal, I
cannot get in touch with the program (It does not process any
messages). I cannot make a loop with Application.ProcessMessages,
since my DLL does not know the Application variable (and should not).

Any solutions?

-- Carsten

---------------------------------------------------------------

"The Dungeon" - RPG homepage: http://inet.uni-c.dk/~alvion/

 

Re:DLL forms shown on a panel


Quote
Carsten Gehling wrote:

> I have a form (F2, that I'd like to show inside a panel (P1) on
> another form (F1).
> That's no problem - I subclass the form and create it with:

> F2 := TMyForm.Create(Application)
> F2.Parent := F1.P1;
> F2.Show;

> However, now I want F2 to reside inside a DLL, so that F1 calls a
> function that displays it:

> unit F1;
> ...
> procedure F2.DisplayForm;
> begin
>   ShowF1(P1);
> end;

> unit F2;
> ...
> procedure ShowF1(AParent : TWinControl);
> begin
>   F2 := TMyForm.Create(nil)
>   try
>     F2.Parent := AParent;
>     F2.Show;  <----------------------- Terminates immediately
>   finally
>     F2.Free;
>   end;
> end;

> F2.Show will terminate after showing it. If I try with ShowModal, I
> cannot get in touch with the program (It does not process any
> messages). I cannot make a loop with Application.ProcessMessages,
> since my DLL does not know the Application variable (and should not).

> Any solutions?

Carsten:

Actually, I can see why F2 terminates immediately: F2.Free gets called
immediately after Show!  Only ShowModal will wait for your form to close
before proceeding any further.  However, as you've noticed, you "can't
get in touch with the rest of your program" with ShowModal implemented.

The solution:  
  I suggest you create 2 new exported API calls in your DLL.  One to
Create
  form F2, and the other to Release form F2.  Just make the ShowF2
function
  above call the Show() method of F2 -- and nothing more!

Also, if your F2 class is defined in your F2 unit (as you call it
above),
then you _do_ have access to the Application variable if you want to use
it.  
After all, the "Forms" unit must be included in your "uses" clause, and
this is where the Application variable resides.

Hope this helps,
-Jim Rofkar.

Other Threads