Catching createing and death of MDI child form.

Posted on 2004-12-01
Medium Priority
Last Modified: 2010-04-05
How can I catch createing and death of MDI child form on parent (MDI) form.

Have a MainForm:TMainForm with FormStyle property set to fs MDIForm. I need to know when child form (the form with FormStyle property set to fs MDIChild) created or destroyed.
Question by:lmikle

Accepted Solution

paulb1989 earned 172 total points
ID: 12720324
In the MDIChild forms unit, add this AFTER implementation:

    uses Form1;

Replace Form1 with the name of the unit with your MDIForm in it.

Now make an event for the oncreate and ondestroy events of the MDIChild form, and in there you can now reference to your main form.


   procedure MyMDIChildCreate(Sender: TObject);

You can then make a procedure on your main form and call it when the MDIChild is created or destroyed.

Author Comment

ID: 12720433
OK. Sorry for inaccuracy.

In a main form I do some work dependencing on MDIChildren list. In child form's OnDestroy it steel contain one and I can't do this work correctly.
LVL 13

Expert Comment

ID: 12721057
you always know when the form is created because you create it right?

if you have it in the autoCreate forms, then it will happen at the very beginning of the application, if you create it in some event (when clicking a button or something) then at that point you create it, and  you can take the other action you need to do at that point, for destroy the form you can use what paulb1989 suggested, just call a method of the main form from the Child form
LVL 27

Assisted Solution

kretzschmar earned 164 total points
ID: 12723556
usual you can define a function or procedure in the mainform,
which is called from the mdichild in the onCloseQuery, onClose or onDestroy

i would prefer the onClose event, because a mdichild should have
a eventproc already


//procedure in mainform
Procedure TMainForm.ChildClose(AChild : TForm);
  //do your stuff here

in you onClose-event of your child

  action := caFree;

to get this work you must include the mainform unit after the implementation-keyword into the uses clause.

meikl ;-)
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 164 total points
ID: 12724826
I wonder if you could use the protected method
    procedure Notification( AComponent: TComponent; Operation: TOperation ); override;

Basically, this method is called whenever a component is added or removed from your form. However, AComponent might not be fully initialized at this moment and it will get triggered for every component on your form. But it will get triggered when you create a childform using the syntax:
  ChildForm := TChildForm.Create(ParentForm);

So I think you could just override this method, call the inherited method first, then check if a form is added or removed.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

809 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