Board index » delphi » Disable the menuitem!

Disable the menuitem!

Hi!

    I'm writing a MDI program. And I want to disable the menuitem of
parent form when the child form is opened. How can I do that? I have
tried to use the main unit (name of main form) in the child form and
it would cause a recursive reference.

-Tan

 

Re:Disable the menuitem!


Quote
H.W. Tan (tan....@bbs3.nsysu.edu.tw) wrote:

: Hi!
:
:     I'm writing a MDI program. And I want to disable the menuitem of
: parent form when the child form is opened. How can I do that? I have
: tried to use the main unit (name of main form) in the child form and
: it would cause a recursive reference.
:
: -Tan

Here are two example I hope will help you.

EXAMPLE #1 : If the child form is not modal.

I have a menu item called Outreach.  In the main form in the Outreach1
OnClick event (the child form is called DataForm) :

procedure TMainForm.Outreach1Click(Sender : TObject);
begin
 DataForm := TDataForm.Create(Application);
 DataForm.Show;
 Outreach1.Enabled := False;
end;

Then in the child form:

procedure TDataForm.FormCreate(Sender : TObject);
begin
 Action := caFree;
 MainForm.Outreach1.Enabled := True;
end;

In the above example, the main form's unit should be included in the USES
clause of the child form's unit.

EXAMPLE #2 : If the form is modal.

In the main form :

procedure TMainForm.Outreach1Click(Sender : TObject);
begin
 Outreach1.Enabled := False;
 DataForm.ShowModal;
 Outreach1.Enabled := True;
end;

In this example, the child form's unit should be placed in the USES clause
of the main form's unit.

More seasoned Delphians in the newsgroup may recommend some exception
handling for both examples to handle cases when the child form has trouble
showing itself.

I hope this helps.  I assume you're doing this (just as I did) to prevent
the user from having more than one instance of the child form present.

Good Luck.

Re:Disable the menuitem!


H|!

Quote
>    I'm writing a MDI program. And I want to disable the menuitem of
>parent form when the child form is opened. How can I do that? I have
>tried to use the main unit (name of main form) in the child form and
>it would cause a recursive reference.

Disable it before opening the child form.

                                        SBR.
---
Bu...@stk.ksu.ras.ru
{Excuse me please for my bad russian, my native language is DELPHI 32-bit}

Re:Disable the menuitem!


Move the uses for the main form into the implementation section.

Quote
H.W. Tan wrote:

> Hi!

>     I'm writing a MDI program. And I want to disable the menuitem of
> parent form when the child form is opened. How can I do that? I have
> tried to use the main unit (name of main form) in the child form and
> it would cause a recursive reference.

> -Tan

--
bgsis...@datasync.com
bgsis...@ocean.st.usm.edu

Other Threads