Page 1 of 1

Count of MDI Child Form

Posted: Fri Aug 07, 2009 2:53 pm
by ConvertFromOldNGs
by Ian Cox >> Mon, 18 Apr 2005 19:29:49 GMT

I wish to code a situation where I disable controls on an MDI Form when the last MDI Child is closed. I have the MDI Child superclass calling a method on its MDI Frame in the form::Unload event I now need a count of the child forms open. DO I need to maintain this or can I get it from the Form/window object?

Re: Count of MDI Child Form

Posted: Fri Aug 07, 2009 2:53 pm
by ConvertFromOldNGs
by T Moore >> Tue, 19 Apr 2005 7:48:55 GMT

You can get the list of forms open using the Application::forms and Application::formsCount methods on the application class. You will need to check the Form::getMDIFrame method to find the forms that are children of the current frame. For example a method on the MDI Frame. Note you may need to exclude the form just closed.

vars
form : Form;
indx : Integer;
iChildCount : Integer;begin

foreach indx in app.formsCount to 1 step -1 do
form := app.forms(indx);
if form.getMdiFrame=self then
// Form is an MDI child of this frame.
iChildCount := iChildCount + 1;
endif;
endforeach;
end;

You could also create an inverse relationship between the MDIFrame and the MDIChild forms. When the MDI child is opened it could set it's MDIFrame reference. Then the count of child forms would simply be the size of the collection.

Torrie