Solved

Delphi Correct way to create and free mdi child forms

Posted on 2009-05-14
2
1,026 Views
Last Modified: 2012-08-14
Good day

What is the correct way to create a mdi child form from a menu and to destroy that form.
All my forms in my applications are not auto created.

Thank you
0
Comment
Question by:henryreynolds
2 Comments
 
LVL 12

Accepted Solution

by:
Hypo earned 125 total points
Comment Utility
If TForm1 is the MDI parent, and TForm2 is the MDI child, then you add the childs by just creating an instance of the child form with the owner form as parent. And to free the form, you assign the FormClose event on TFrame2, and set CloseAction to caFree when the event fires. This will cause the Form to be freed when the user closes the form. (Don't forget to set the FormStyle property on both TForms)

See examples below:

/Hypo


implementation

{$R *.dfm}

uses Unit2; // <- In Unit1, you add the child MDI unit below the implementation line so that you don't get circular references.  
 

// In your menu, you create a child form class and set Self as Owner...

procedure TForm1.NewChild1Click(Sender: TObject);

begin

  Tform2.Create(Self);

end;
 

...

// In your MDI child's OnClose
 

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);

begin

  Action := caFree; // <- causes the form to be freed... 

end;

Open in new window

0
 

Author Comment

by:henryreynolds
Comment Utility
Hi Hypo

Thank you.

Keep well
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now