Delphi Multi-Document Interface or MDI


To show how this work, just create two(2) Form and have the 1st form's FormStyle property set to fsMDIForm and the 2nd as fsMDIChild.


Please make sure that Auto-Create form (new feaature adopted from Delphi 5.0) under the Project option is set to False.


Generally, however, the child form is not created at startup, and you need to provide a way to create one or more child windows. This can be done by adding a menu with a New menu item and writing the following code:


procedure TForm1.btnSingleClick (Sender: TObject);

begin

   if not Assigned (Form2) then

        Form2 := TForm2.Create

        (Application);

   Form2.Show;

end;


with this code, the form is created the first time it is required and then is kept in memory, visible on the screen or hidden from view.  To avoid using up memory and system resources unnecessarily, you'll want to destroy the secondary form when it is closed. You can do that by writing a handler for the OnClose event:


procedure TForm2.FormClose

     (Sender: TObject;

var Action: TCloseAction);

begin

        Action := caFree;

        

        // important set pointer

        // to nil

        Form2 := nil;

end;


Form Constraints


to fix the size of the Form(window box) created as a Child, use the following option:


ex.:


   Constraints.MaxHeight := 300;

   Constraints.MaxWidth := 300;

   Constraints.MinHeight := 150;

   Constraints.MinWidth := 150;


Set's the limit of the current Form and should be placed inside the Form Create procedure.


Border style should be set to Single only so to retain the actual design time window size or area.