Link to home
Start Free TrialLog in
Avatar of Raven1155
Raven1155Flag for United States of America

asked on

MDI program and DLL's

I want to write a D4 program which has 4 major sections (Customers, Catalog, Orders, Sales Staff).  I'd prefer to write it as one big MDI program, with each section having it's own window(s).  However, I'd ALSO like to be able to incrementally upgrade it, i.e., if I write an improvement for the Catalog section, I don't want to have to replace the ENTIRE program.

I've tried looking through D4's help files, and can't find out if this is do-able.  Could y'all please tell me-
1.  Is it even possible?
2.  Is it discussed in D4 help, or in some other source?
3.  Any suggestions you might have would be appreciated...

Thanks in advance!!
 Jim 8^}
Avatar of philipleighs
philipleighs

Hi,

There are many ways of doing this, but you have to give ample thought into you architecture before hand.

You are effectively talking about plugins (I think). You have to design a standard interface that each dll will have, and have some way of registering them. If you're a COM hotshot then this is perfect.

If not, then have a "PlugIns" menu on your main form, and in the FormCreate event enumerate your DLLs and call the "GetPlugInName" function that each dll will have so that you can populate the menu. The function returns a string that will added to your menu.
When a menu item is clicked, call your "DoIt" function which is in each DLL with a pointer to some data. You'll have to find out about dynamically loading DLLs.
Use LoadLibrary, GetProcAddress, FreeLibrary.

You could have many types of "DoIt" functions (unique names of course) that take different types of data.

If the updates are not really plugin-like, but more like bug fixes and new features or UI changes, then this approach is not suitable.

It you want something like PhotoShop where other people (or you) can extend your app by adding their own image filters, then this approach is good.

Remember, anything is possible with Delphi.

Food for thought,
Phil.
Avatar of Raven1155

ASKER

Thank you for your comments, but I'm >not< talking about Plugins!

I already know that I can write a large program, with many units, with MDIChild forms whose units hold the code for the various program segments.  However, this results in one LARGE executable.  To fix a problem, or change a capability, in any of the sections (Customer, Catalog, etc.), I have to replace the whole thing!

What I'm trying to figure out is- is it possible to write the code for an MDIChild form as a DLL (i.e., separate from the main program)?!?!  The kind of thing I'm thinking of here is the ability to upgrade PART(s) of a program (e.g., Norton Utilities LiveUpdate, or AOL's Tool Update).

This is the kind of thing I'm asking for, not "anything is possible with Delphi"!

- J. Sky

PS- Also, I apologize if y'all thought I was asking you to write code for me... as nice as that is, I'm trying to find out where I can READ more about the architecture possibilities!
OK, ok,

There is a chapter in the Developer Guide (D3) about wrapping a TForm in a DLL "Building a Dialog Box into a DLL"

Might be helpful.


I don't have the developer's guide, but will see what I can find relating to that general topic.  Thank you very much!

Any other suggestions would be (are) appreciated...
ASKER CERTIFIED SOLUTION
Avatar of Thaddy
Thaddy

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
Ofcourse you should DERIVE from the customclass and THEN add your code to the derived new custom class, but I think that was obvious.
Since I'm not an expert, and don't feel qualified to become one, I have to put this comment here.  Experts, PLEASE pass it onto others who've asked this question...

To get an MDI app. to recognize child windows from DLLs >FULLY< (i.e., in MDIChildCount, etc.), I simply modified Thaddy's answer to me SLIGHTLY... {my changes are in ALL Caps}

Here's the code for the MDI Child DLL (Put "action:=caFree" in the child forms' "Close Form" event!, and call the DLL form from the main app with "ShowMDIChildForm(Application, SCREEN);")-
---
library MDIForms;


uses
  SysUtils,
  Classes,
  Forms,
  Windows,
  ChildU in 'ChildU.pas' {ChildForm};

var
 DLLApp: TApplication;
 DLLSCRN: TSCREEN;  //MY CHANGE

procedure MyDllProc(Reason:Integer);
begin
 if Reason = DLL_PROCESS_DETACH then
  if Assigned(DllApp) then
  begin
   Application:=DllApp;
   SCREEN:=DLLSCRN;  //MY CHANGE
  end;
end {MyDllProc};

procedure ShowMDIChildForm(MainApp:TApplication; MAINSCRN:TSCREEN);    //added MAINSCRN variable..
var Child:TChildForm;
begin
 If not Assigned(DllApp) then
 begin
  DllApp:=Application;
  DLLSCRN:=SCREEN;   //My Change
  Application:=MainApp;
  SCREEN:=MAINSCRN;  //My Change
 end;
 Child:=TChildForm.Create(Application.MainForm);
 Child.Show;
end {ShowMDIChildForm};
 exports ShowMDIChildForm;
begin
 DllApp:=nil;
 DllScrn:=nil;
 DLLProc:=@MyDllProc;
end.
---
By adding the connection to the Screen global variable, the Forms unit now adds the child form(s) to the MDIForm just as if you'd written the code as a unit that is part of the main app!

Cheers,
 Jim 8^)