Solved

Delphi Correct way to create and free mdi child forms

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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