[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


MDI program and DLL's

Posted on 1998-10-18
Medium Priority
Last Modified: 2010-04-06
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^}
Question by:Raven1155
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2

Expert Comment

ID: 1343300

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,

Author Comment

ID: 1343301
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!

Expert Comment

ID: 1343302
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.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1343303
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...

Accepted Solution

Thaddy earned 600 total points
ID: 1343304
Yes you can. It's very easy, provided you design your application carefully.
Make Shure there are no dependencies between class hierarchies.
Always define a Custom class, that precedes the working class,
implement this custom with as much functionality as possible and almost anything protected (or public, if it should be)
Publish the things you need in the final class.
Then, if you want to implement new functionality, go back to the customclass (that has proven code) and add the new functionality, or improved functionality to the custom class.
What you have now can be a) A new Custom class (if you've added to the class) or b) a new final class ( if just the implementation changed.)
This way you never break existing code and have a clear way of understanding how and why an application has evolved.

Here's code for the mdi child dll:
You might be interest in this little snippet.
Design your form, add action:=caFree to the formclose event!
and compile it in this dll framework. You call the dll form from your main app like so: ShowMDIChildForm(Application);

library MDIForms;
  SysUtils, Classes,Forms,Windows,ChildU in 'ChildU.pas' {ChildForm};
  DLLApp : TApplication;
procedure MyDLLProc(Reason: Integer);
  if Reason = DLL_PROCESS_DETACH then
    if Assigned(DllApp) then
      Application := DllApp;
procedure ShowMDIChildForm(MainApp : TApplication);
  Child : TChildForm;
  if not Assigned(DllApp) then begin
    DllApp := Application;
    Application := MainApp;
  Child :=TChildForm.Create(Application.MainForm);
  DllApp := nil;
  DLLProc := @MyDLLProc;


Expert Comment

ID: 1343305
Ofcourse you should DERIVE from the customclass and THEN add your code to the derived new custom class, but I think that was obvious.

Author Comment

ID: 1343306
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;

  ChildU in 'ChildU.pas' {ChildForm};

 DLLApp: TApplication;

procedure MyDllProc(Reason:Integer);
 if Reason = DLL_PROCESS_DETACH then
  if Assigned(DllApp) then
end {MyDllProc};

procedure ShowMDIChildForm(MainApp:TApplication; MAINSCRN:TSCREEN);    //added MAINSCRN variable..
var Child:TChildForm;
 If not Assigned(DllApp) then
  DLLSCRN:=SCREEN;   //My Change
  SCREEN:=MAINSCRN;  //My Change
end {ShowMDIChildForm};
 exports ShowMDIChildForm;
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!

 Jim 8^)

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question