tags:

views:

164

answers:

2

Hi,

Simple task: I would like to make a program (parent.exe). There are three buttons. When I click Button1, Form1 appears; when Button 2, Form2 appears; when Button3, Form3 appears...

Form1, Form2, Form3 are stored in three different dlls (Form1dll.dll, Form2dll.dll, Form3dll.dll).

I wanted to make parent program (parent.exe) run modular. I planned to add and remove dlls, but Parent.exe requires all dlls to be present, otherwise an exception occures.

How can I solve the problem?

Thanx

Here is code from parent.exe:

  procedure ShowForm1;stdcall;external 'Project1dll.dll' name 'ShowForm1';
  procedure ShowForm2;stdcall;external 'Project2.dll' name 'ShowForm2';
  procedure ShowForm3;stdcall;external 'Project3.dll' name 'ShowForm3';

var
  ParentForm: TParentForm;

implementation

{$R *.DFM}



procedure TParentForm.Button1Click(Sender: TObject);
begin
  ShowForm1;
end;

procedure TParentForm.Button2Click(Sender: TObject);
begin
  ShowForm2;
end;

procedure TParentForm.Button3Click(Sender: TObject);
begin
  ShowForm3;
end;
+5  A: 

The way you've got it set up, the program looks for the DLLs at load time. What you need is to set the DLLs up as plugins. Take a look at the JVPlugin framework in the JVCL. It has exactly what you're looking for.

Mason Wheeler
You should enable Runtime Packages before attempting to use Plugins (JVPlugin or any other). You must load the core RTL/VCL classes from a package, instead of statically linking them, so that one common copy of all core shared Class code and data structures are shared among your main application and its plugins.
Warren P
Yes, but only if you use BPLs for the plugins. It's possible to use DLLs too.
Mason Wheeler
+4  A: 

Yes it can by having the EXE Dynamically load the DLLs using LoadLibrary and GetProcAddress. See http://www.scalabium.com/faq/dct0130.htm for an example.

Next you might run into other problems because the memory manager and types are not shared between the EXE and the different DLLs. You might need to take extra care to circumvent these problems or look for solutions. Like runtime packages/BPLs or special memory managers.

Lars Truijens