Solved

Delphi Correct way to create and free mdi child forms

Posted on 2009-05-14
2
1,074 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 128
HTML text in the body of an email (delphi code) 12 112
LAN or WAN ? 11 90
Firemonkey android show image from resource ? 1 41
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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