Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MDIChild closes MDIChildren

46 views
Skip to first unread message

Ed Dressel

unread,
Mar 2, 1999, 3:00:00 AM3/2/99
to
Several things to note:

MDIChildCount is the property of the main form. The current form
also has the property MDIChildCount--but it doesn't have any children.
Therefore, MDIChildCount is always zero. Change the code (also note the
different order of the loop) to:


For I := MainForm.MDIChildCount -1 to 0 do // MainForm is needed, also
reverse the loop order
if MainForm.MDIChildren[i] is Self then //you could try 'self' here
MainForm.MDIChildren[I].Close;

Ed Dressel


Wasis Sugiono wrote:

> Can a child form close other child forms (of MDIMain) ?
>
> Here's the code. But other child forms can not be closed.
>
> procedure TProperties.Button2Click(Sender: TObject);
> begin
>
> {Close all the windows except this one}
> {MDIChildCount is always 0}
> For i := 0 to MDIChildCount - 1 do
> If not (MDIChildren[i] is TProperties) Then
> MDIChildren[i].Close;
> End;
>
> Could u tell me what's wrong with it?
>
> Thanks in advance.


Wasis Sugiono

unread,
Mar 3, 1999, 3:00:00 AM3/3/99
to

Wasis Sugiono

unread,
Mar 3, 1999, 3:00:00 AM3/3/99
to

> MDIChildCount is the property of the main form. The current form
> also has the property MDIChildCount--but it doesn't have any children.
> Therefore, MDIChildCount is always zero. Change the code (also note the
> different order of the loop) to:
>
> For I := MainForm.MDIChildCount -1 to 0 do // MainForm is needed, also
> reverse the loop order

However if the order is forward, I get the same result. Does it sound
strange?


> if MainForm.MDIChildren[i] is Self then //you could try 'self' here
> MainForm.MDIChildren[I].Close;

It doesn't work.

Ralph Friedman (TeamB)

unread,
Mar 3, 1999, 3:00:00 AM3/3/99
to
Wasis,

you need to use the MDIChildCount and MDIChildren properties of the MDIClient
form. e.g.:

procedure TProperties.Button2Click(Sender: TObject);
begin
with MDIClient do
begin


For i := 0 to MDIChildCount - 1 do
If not (MDIChildren[i] is TProperties) Then
MDIChildren[i].Close;

end;
End;


--
Regards
Ralph (TeamB)
--
Wasis Sugiono wrote in message <36DC4CB0...@rad.net.id>...


Ralph Friedman (TeamB)

unread,
Mar 3, 1999, 3:00:00 AM3/3/99
to
Wasis,

you were supposed to substitute the name of _your_ MDI Client form for that.
Move "uses Main" to the implementation section and it will take care of the
circular reference.

--
Regards
Ralph (TeamB)
--

Wasis Sugiono wrote in message <36DD7A7D...@rad.net.id>...
|Ralph,


|
|
|> procedure TProperties.Button2Click(Sender: TObject);
|> begin
|> with MDIClient do
|> begin
|> For i := 0 to MDIChildCount - 1 do
|> If not (MDIChildren[i] is TProperties) Then
|> MDIChildren[i].Close;
|> end;
|> End;
|

|This doesn't work. It causes an error: "Undeclared indentifier: 'MDIClient' "
|
|I use this:
| For i := Main.MDIChildCount - 1 DownTo 0 Do
| If not (Main.MDIChildren[i] is TProperties) Then
| Main.MDIChildren[i].Close;
|
|This works but it's not good enough because I have to add:
|Uses
| Main
|
|Look, Main uses Properties and Properties uses Main. It's like a circular
loop.


Wasis Sugiono

unread,
Mar 4, 1999, 3:00:00 AM3/4/99
to
Ralph,


> procedure TProperties.Button2Click(Sender: TObject);
> begin
> with MDIClient do
> begin
> For i := 0 to MDIChildCount - 1 do
> If not (MDIChildren[i] is TProperties) Then
> MDIChildren[i].Close;
> end;
> End;

This doesn't work. It causes an error: "Undeclared indentifier: 'MDIClient' "

I use this:
For i := Main.MDIChildCount - 1 DownTo 0 Do
If not (Main.MDIChildren[i] is TProperties) Then
Main.MDIChildren[i].Close;

This works but it's not good enough because I have to add:
Uses
Main

Look, Main uses Properties and Properties uses Main. It's like a circular loop.

I also have another question. This question is a reply to a message of
borland.public.delphi.winapi. It's about how to find out which MDI-Child is
opened.

Let's say I have a form THandOuts and the var is HandOuts. If there is one
instance of THandOuts, a new one can't be created.

procedure TMain.Handouts1Click(Sender: TObject);
begin
{Error: Incompatible types: TObject and Class reference}
If AlreadyExist(THandOuts) Then
Exit;

with THandouts.Create(self) do
Show;
End;

Function TMain.AlreadyExist (AnObject : TObject) : Boolean;
Var
i : Integer;
Begin
Result := False;


For i := 0 to MDIChildCount - 1 do

If MDIChildren[i] is AnObject then
Begin
MDIChildren[i].BringToFront;
Result := True;
Break;
End;
End;

procedure THandouts.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;

I don't know what's wrong with it. If I change the parameter's value become
HandOuts, the error is error no 405.

I think the problem is the parameter type.

Thanks


Wasis Sugiono

unread,
Mar 4, 1999, 3:00:00 AM3/4/99
to
How about my next question?


Ralph Friedman (TeamB)

unread,
Mar 4, 1999, 3:00:00 AM3/4/99
to
Wasis,

sorry, I hadn't scrolled down far enough to see it. Changing the declaration
to:

Function TMain.AlreadyExist (AForm: TForm): Boolean;

should do it for you.


--
Regards
Ralph (TeamB)
--

Wasis Sugiono wrote in message <36DD928C...@rad.net.id>...

0 new messages