Board index » cppbuilder » TMainMenu problem

TMainMenu problem

I'm creating a BPL function that receives a TMainMenu component and sets all
of the menu items to the property  Disabled = false.

I'm having a hard time to understand the structure of a TMainMenu.

This is what I can understand by having read the help files on this subject.

TMainMenu
|--->contains TMenu "s"
   |--->contains TMenuItems "s"

The problem is looping through all of the menu items including all sub menu
items.
i.e:
for(intCur = 0; intCur < Menu->Items->Count; intCur++)
{
    code here

Quote
}

The function that will be called after this one is to enable certain menu
items corresponding to the system user.  I will not be needing help fo this
function because it will be very similar as the one I'm asking about.
 

Re:TMainMenu problem


If you want to set disable every menu item of a particular menu I would
suggest
you to use a recursive method...

probably something like that

void __fastcall TForm1::SetMenuProp(TMenuItem* pItem, bool bEnabled, bool
bRecursive)
{
    if (pItem == NULL) return;

    pItem->Enabled = bEnabled;

    if (bRecursive)
  {
        for (int i = 0; i < pItem->Count; i++)
             SetMenuProp(pItem->Items[i], bEnabled, bRecursive);
    }

Quote
}

good luck

Quote
Stephane Baillargeon <mbaillarg...@sympatico.ca> wrote in message

news:3bfc100b_2@dnews...
Quote
> I'm creating a BPL function that receives a TMainMenu component and sets
all
> of the menu items to the property  Disabled = false.

> I'm having a hard time to understand the structure of a TMainMenu.

> This is what I can understand by having read the help files on this
subject.

> TMainMenu
> |--->contains TMenu "s"
>    |--->contains TMenuItems "s"

> The problem is looping through all of the menu items including all sub
menu
> items.
> i.e:
> for(intCur = 0; intCur < Menu->Items->Count; intCur++)
> {
>     code here
> }

> The function that will be called after this one is to enable certain menu
> items corresponding to the system user.  I will not be needing help fo
this
> function because it will be very similar as the one I'm asking about.

Re:TMainMenu problem


I've already guessed that I had to build a recursive function but the thing
is that I  have a hard time understanding where bEnabled and bRecursive come
from.  Where are they set?  Please explain the flow of the function that you
described.

Thank you.

Quote
"Stephane Baillargeon" <mbaillarg...@sympatico.ca> wrote in message

news:3bfc100b_2@dnews...
Quote
> I'm creating a BPL function that receives a TMainMenu component and sets
all
> of the menu items to the property  Disabled = false.

> I'm having a hard time to understand the structure of a TMainMenu.

> This is what I can understand by having read the help files on this
subject.

> TMainMenu
> |--->contains TMenu "s"
>    |--->contains TMenuItems "s"

> The problem is looping through all of the menu items including all sub
menu
> items.
> i.e:
> for(intCur = 0; intCur < Menu->Items->Count; intCur++)
> {
>     code here
> }

> The function that will be called after this one is to enable certain menu
> items corresponding to the system user.  I will not be needing help fo
this
> function because it will be very similar as the one I'm asking about.

Re:TMainMenu problem


I've already guessed that I had to build a recursive function but the thing
is that I  have a hard time understanding where bEnabled and bRecursive come
from.  Where are they set?  Please explain the flow of the function that you
described.

Thank you.

Quote
"Rick Golden" <GoldenR...@hotmail.com> wrote in message

news:3bfc192d_2@dnews...
Quote
> If you want to set disable every menu item of a particular menu I would
> suggest
> you to use a recursive method...

> probably something like that

> void __fastcall TForm1::SetMenuProp(TMenuItem* pItem, bool bEnabled, bool
> bRecursive)
> {
>     if (pItem == NULL) return;

>     pItem->Enabled = bEnabled;

>     if (bRecursive)
>   {
>         for (int i = 0; i < pItem->Count; i++)
>              SetMenuProp(pItem->Items[i], bEnabled, bRecursive);
>     }

> }

> good luck

> Stephane Baillargeon <mbaillarg...@sympatico.ca> wrote in message
> news:3bfc100b_2@dnews...
> > I'm creating a BPL function that receives a TMainMenu component and sets
> all
> > of the menu items to the property  Disabled = false.

> > I'm having a hard time to understand the structure of a TMainMenu.

> > This is what I can understand by having read the help files on this
> subject.

> > TMainMenu
> > |--->contains TMenu "s"
> >    |--->contains TMenuItems "s"

> > The problem is looping through all of the menu items including all sub
> menu
> > items.
> > i.e:
> > for(intCur = 0; intCur < Menu->Items->Count; intCur++)
> > {
> >     code here
> > }

> > The function that will be called after this one is to enable certain
menu
> > items corresponding to the system user.  I will not be needing help fo
> this
> > function because it will be very similar as the one I'm asking about.

Other Threads