Catching createing and death of MDI child form.

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.
LVL 3
lmikleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paulb1989Commented:
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.

eg:

   procedure MyMDIChildCreate(Sender: TObject);
   begin
     Form1.DoSomething;
   end;

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lmikleAuthor Commented:
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.
0
BlackTigerXCommented:
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
0
kretzschmarCommented:
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

sample

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

in you onClose-event of your child

...
begin
  MainForm.ChildClose(self);  
  action := caFree;
end;

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

meikl ;-)
0
Wim ten BrinkSelf-employed developerCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.