Board index » delphi » MDI Children HELP - Making Buttons Visible or not

MDI Children HELP - Making Buttons Visible or not

Does anyone know how to create a variable or procedure that will sync my MDI application
to know if any MDIChildren currently exist or not??

If there is no child forms open, I would like to make the appropriate buttons invisable.

I tried using the code in the function below done two ways, with the current IF statement
and the one directly below it remmed out.  Both compiled, but did not control the buttons
visibility at all.

---------------------------------------------------------
procedure TMDIChild1.Close1Click(Sender: TObject);
begin
Close;
if Mainform.MDIChildCount = -1 then
{if MDIChild1 = nil then}
 MainForm.CopyMenuBtn.Visible := False;
 MainForm.CutMenuBtn.Visible := False;
 MainForm.PasteMenuBtn.Visible := False;
 MainForm.DeleteMenuBtn.Visible := False;
end;

----------------------------------------------------------

Can you offer a suggestion to cure this??

Thanks
----
RKR

****************************************
E-Mail:  r...@primenet.com
****************************************

 

Re:MDI Children HELP - Making Buttons Visible or not


Quote
r...@primenet.com wrote:
>Does anyone know how to create a variable or procedure that will sync my MDI application
>to know if any MDIChildren currently exist or not??
>If there is no child forms open, I would like to make the appropriate buttons invisable.
>I tried using the code in the function below done two ways, with the current IF statement
>and the one directly below it remmed out.  Both compiled, but did not control the buttons
>visibility at all.
>---------------------------------------------------------
>procedure TMDIChild1.Close1Click(Sender: TObject);
>begin
>Close;
>if Mainform.MDIChildCount = -1 then
>{if MDIChild1 = nil then}
> MainForm.CopyMenuBtn.Visible := False;
> MainForm.CutMenuBtn.Visible := False;
> MainForm.PasteMenuBtn.Visible := False;
> MainForm.DeleteMenuBtn.Visible := False;
>end;
>----------------------------------------------------------
>Can you offer a suggestion to cure this??

Try this:

        MainForm.CopyMenuBtn.Visible := (MainForm.MDIChildCount > 0);
        MainForm.CutMenuBtn.Visible  := (MainForm.MDIChildCount > 0);
        MainForm.PasteMenuBtn.Visible := (MainForm.MDIChildCount > 0);
        MainForm.DeleteMenuBtn.Visible := (MainForm.MDIChildCount > 0);

One of the problems was that you were checking to see if the count was
-1.  This should never happen.  It should be 0 or higher.  

Another thing you may wish to consider, is changing the Visibile to
Enabled so it would look like:

        MainForm.CopyMenuBtn.Enabled := (MainForm.MDIChildCount > 0);
        MainForm.CutMenuBtn.Enabled  := (MainForm.MDIChildCount > 0);
        MainForm.PasteMenuBtn.Enabled := (MainForm.MDIChildCount > 0);
        MainForm.DeleteMenuBtn.Enabled := (MainForm.MDIChildCount > 0);

The buttons remain visible, but the user can not select them, and they
are "Greyed" out.

Brien King
bk...@primenet.com

Re:MDI Children HELP - Making Buttons Visible or not


Quote
>---------------------------------------------------------
>procedure TMDIChild1.Close1Click(Sender: TObject);
>begin
>Close;
>if Mainform.MDIChildCount = -1 then
>{if MDIChild1 = nil then}
> MainForm.CopyMenuBtn.Visible := False;
> MainForm.CutMenuBtn.Visible := False;
> MainForm.PasteMenuBtn.Visible := False;
> MainForm.DeleteMenuBtn.Visible := False;
>end;

>----------------------------------------------------------

I always managed to hide or show my components by setting their
Visible property. I don't know if this will solve your problem but
I believe you *must* have a begin...end pair of keywords in your
if statement, otherwise only the first statement following your if
condition will be executed.

procedure TMDIChild1.Close1Click(Sender: TObject);
begin
Close;
if Mainform.MDIChildCount = -1 then {if MDIChild1 = nil then}
  begin
   MainForm.CopyMenuBtn.Visible := False;
   MainForm.CutMenuBtn.Visible := False;
   MainForm.PasteMenuBtn.Visible := False;
   MainForm.DeleteMenuBtn.Visible := False;
  end;
end;

Catalin

Re:MDI Children HELP - Making Buttons Visible or not


A neat trick I use in both VB and Delphi is to place all my "to be hidden"
controls in a Picture Box (VB) or a Panel (Delphi), then just hide the
container.  That way I only need one

  Container.Visible:=True;

command.

Cheers!

Other Threads