2

I'm building a form inside a DLL and would like to embed that form inside the host application. Surely I can't simply pass the Parent control into the DLL. But I have to give this DLL form a Parent from the EXE form (inside a TPanel).

How can I make this form inside the DLL embedded inside its host application, aligned as Client within a panel?

What I'm building is a setup module which consists of a tree view on the left half of the form, and an empty placeholder panel on the right, like a snap-in console. Each possible module is represented by a DLL, one corresponding with each node on the tree view.


EDIT

One important thing I didn't mention before, the reason I'm implementing DLL's is because each setup module might be developed in a different language. Most will be Delphi, But the software package which this is based around consists of different applications built in some other languages than Delphi (such as C#). Those developers will design their own setup modules to be integrated.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327

3 Answers3

5

I don't know if this will address all the issues (save freeing the form, I would expose functions to do anything external involving the dll form), but this should give a good start:

library testdll;

uses dllunit in 'dllunit.pas' {Form1}, windows;

procedure callform(ParentForm: HWnd);
// simple test, resource management is necessary on the form.
var
  dllform: TForm1;
begin
  dllform := TForm1.Create(nil);
  dllform.Show;
  Windows.SetParent(dllform.Handle, ParentForm);
end;

exports
  callform;

end.


program mainprogram;

procedure callform(ParentHandle: THandle); external 'testdll.dll';

procedure TForm1.Button1Click(Sender: TObject);
  begin
    callform(Panel1.Handle);
  end;

Like was said, there might be other issues once you start adding features to the dll form, but (for me) it's putting the form designed in dllunit.pas into the main form's project with Panel1 as a parent and is operating as expected. But like was said, this was just intended as a start.

Johan
  • 74,508
  • 24
  • 191
  • 319
Glenn1234
  • 2,542
  • 1
  • 16
  • 21
4

If the parent is another Delphi program, you could simply make your DLL as a BPL, and then you shouldn't have problems with stuff like this. Have a look at the plugin system in the JVCL for a way to make it easy to plug new functionality into your program with packages.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
0

Yes, it is the handle, just call it to fill any component like a Groupbox or Panel