share this

First, we'll create an MDI type of application:

Here are the steps:

1. Create a new MDI application. You can even use the MDI Application wizard (File - New - Other - Projects - MDI Application).
2. Make sure FormStyle property of the main form is set to fsMDIForm.
3. Add a main menu to the application. Let it have one item - the one that loads the MDI child from the Package.

MDI module parent
4. Make sure you build the application using run-time packages. Go to Project-Options, select the Packages tab, and check the "Build with run-time packages". You should at least use the rtl and the vcl package.

Project-Options - built with packages

Before writing some actual Delphi code, let's first build the package and add one MDI child form to it.

1. Start by creating a run-time package.
2. Add a TForm object to the package. Make sure FormStyle property is set to fsMDIChild.
3. Add one exported procedure to create an instance of the child form:

procedure TPackageMDIChildForm.FormClose
(Sender: TObject;
var Action: TCloseAction);
//since this is an MDI child, make sure
//it gets closed when the user
//clicks the x button.
Action := caFree;

procedure ExecuteChild;

//NOTE!! The export name


Going back to the MDI host application...

Here's the entire code in the main MDI form:

//signature of the "ExecuteChild"
//procedure from the Package
TExecuteChild = procedure;

TMainForm = class(TForm)
PackageModule : HModule;
ExecuteChild : TExecuteChild;
procedure PackageLoad;

MainForm: TMainForm;

{$R *.dfm}

procedure TMainForm.PackageLoad;
//try loading the package
//(let's presume it's in the same
//folder, where the main app. exe is)
PackageModule := LoadPackage('MDIPackage.bpl');

//if loaded, try locating
//the ExecuteChild procedure
if PackageModule <> 0 then
@ExecuteChild := GetProcAddress(PackageModule,
//display an error message if we fail
ShowMessage ('Package not found');

//menu click
procedure TMainForm.mnuCallFromDLLClick
(Sender: TObject);
//lazzy load package
if PackageModule = 0 then PackageLoad;

//if the ExecuteChild procedure
//was found in the package, call it
if Assigned(ExecuteChild) then ExecuteChild;

procedure TMainForm.FormDestroy(Sender: TObject);
//if the package was loaded,
//make sure to free the resources
if PackageModule <> 0 then

The above code, dynamically loads (PackageLoad procedure) the package as needed (when menu item is selected) and unloads the package when the application terminates. If you need help with the code, check the "Dynamic Form in Dynamic Package" article.

Finally, at run time, we have an MDI child form loaded from a package and working happily inside an MDI parent form:

Packaged MDI Child form inside an MDI parent

One final note: when modularizing applications using run-time packages, you have to redistribute the required packages along with the application's exe file.

That's it! As simple as it can be.
Related Articles

* A Beginner’s Guide to Delphi Programming - Chapter 11
* Your First MDI Delphi Project
* MDI Development in Delphi. Part I.
* MDI Development in Delphi. Part II.
* Dynamic World of Packages - page 1/3

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

* Sign up for my Newsletter

* My Blog
* My Forum

optical sensor LCD pad on notebook PC

Sharp Corp on Tuesday said it will release a new notebook PC employing an optical sensor LCD for the touchpad. Its new touch-sensing recognition method allows handwritten input and intuitive direct-touch operation. The notebook will cost around 80,000 yen and go on sale in late May.
The 4-inch optical sensor LCD pad in this notebook PC is more than just a conventional track pad thanks to its new touch-sensing recognition method: in addition to conventional mouse operation, it allows pen-based input of drawings and text, as well as multiple-finger-touch operation (gestures) to enlarge, shrink, or rotate items on the screen. For example, users can sign their name to an on-screen photo before emailing it, or they can use two fingers to zoom in and out of Internet Web sites to make them just the right size for viewing. Unlike regular touch panels, Sharp’s optical sensor LCD pad requires no touch sensor or protective film, so illustrations and photos are crystal clear. And the large effective operation area allows for more freedom of movement.
In the future, Sharp will expand the possibilities for its notebook PCs by developing software that makes the most of the optical sensor LCD pad