Catching createing and death of MDI child form.

Posted on 2004-12-01
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
    LVL 5

    Accepted Solution

    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.
    LVL 3

    Author Comment

    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

    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

    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
    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now