Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi Correct way to create and free mdi child forms

Posted on 2009-05-14
2
Medium Priority
?
1,449 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
[X]
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
2 Comments
 
LVL 12

Accepted Solution

by:
Hypo earned 500 total points
ID: 24384544
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
ID: 24384635
Hi Hypo

Thank you.

Keep well
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 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