Solved

How to close all?

Posted on 1998-02-10
17
148 Views
Last Modified: 2010-04-04
how do i close all my child MDI forms in
 the master MDI Form?
How do i make the child MDI Forms change/minised into icons?
0
Comment
Question by:superboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
17 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1358889
To minimize:
var
  I: Integer;
begin
  with Form1 do
    for I := MDIChildCount-1 downto 0 do
      MDIChildren[I].Close;
end;

To Close:
begin
  with Form1 do
    while MDIChildCount>0 do
      MDIChildren[0].Release;
end;
0
 

Author Comment

by:superboy
ID: 1358890
can u write the full code?
what is the MDIChildCount and MDIChildren?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358891
What full code?
From Delphi Help file:

property MDIChildCount: Integer;

Run-time and read-only. The value of the MDIChildCount property is the number of child windows open in an MDI application.
----------------------------------------
property MDIChildren[I: Integer]: TForm;

Run-time and read-only. The MDIChildren property array provides access to a child window or form in an MDI application through an index value, I. The value of I is determined by the order in which the window was created. For example, the first MDI child window has an I value of 0.
----------------------------------------
property ActiveMDIChild: TForm;

Run-time and read only. The value of the ActiveMDIChild property is the form that currently has focus in an MDI application. This only applies if the form is of type fsMDIForm.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:superboy
ID: 1358892
must i declare the variables MDIChildCount, MDIChildren
 and so on?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358893
No, It is already declared as a property. Delphi "knows" how many
childs are opened, and how to access them.
0
 

Author Comment

by:superboy
ID: 1358894
if i minismised the forms into icons..
will delphi assigned some default icons to the forms
and can i do a arrangeicons after that?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358895
Yes.
0
 

Author Comment

by:superboy
ID: 1358896
how do i add a message dialog when closing each MDI Child form?
like to confirm whether the user want to close../or he want to save what he has done in the MDI child form?

is there a way to check if something is written in the MDI child form when i has a memo in the child form...?
0
 

Author Comment

by:superboy
ID: 1358897
hey ronit, i try your method
To Close:
               begin
                 with Form1 do
                   while MDIChildCount>0 do
                   MDIChildren[0].Release;
               end;
and it crash my application...

the minimise code u wrote, i try it and it is actually for the
close all function...what abt minimised to icons?

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358898
I am checking...
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358899
Sorry my mistake. If you use Delphi 3, write the following code:

To Minimize:

procedure TMainForm.Button1Click(Sender: TObject);
var I: byte;
begin
LockWindowUpdate(Handle);
if MDIChildCount>0 then
  for I := MDIChildCount-1 downto 0 do
    MDIChildren[I].WindowState:=wsMinimized;
LockWindowUpdate(0);
end;

To close:
procedure TMainForm.Button1Click(Sender: TObject);
var I: byte;
begin
LockWindowUpdate(Handle);
if MDIChildCount>0 then
  for I := MDIChildCount-1 downto 0 do
    MDIChildren[I].Close;
LockWindowUpdate(0);
end;

and on the OnClose event of the child form write:
Action:=cafree;
0
 

Author Comment

by:superboy
ID: 1358900
LockWindowUpdate(Handle);
what does this do?
0
 

Author Comment

by:superboy
ID: 1358901
how do i restore all the MDI child windows to their previous
windowstate ? i want to do something like tile..but it does not work..
0
 
LVL 4

Expert Comment

by:d003303
ID: 1358902
you can use the Cascade, Tile and ArrangeIcons methods of the MDI parent for that.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358903
LockWindowUpdate(handle) freezes the screen until you call LockWindowUpdate(0). This, in order to increase performance.
0
 

Author Comment

by:superboy
ID: 1358904
LockWindowUpdate(handle) does this make any app hang?
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358905
No, It's just preventing from screen to be refreshed while something is being processed.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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