Board index » cppbuilder » Switch menu

Switch menu


2004-02-12 12:55:21 AM
cppbuilder112
Hi!!!
I've a problem.
I've a MDIForm with 2 menu (1 empty and 1 full)
When the application start i charge the empty menu, after I show a login
form if
the user is logged correctly, i want to change the empty menu with the full
one.
How is possible??
Thank you in advance
Bye
Pietro
 
 

Re:Switch menu

If the user presses the Mode1 button, the Menu structure is
changed......
void __fastcall TForm1::Mode1Click(TObject *Sender)
{
// switch between working on the Elements and Base Shapes mode
if ( Mode1->Caption=="&Elements" )
{
Mode1->Caption = "&Base Shapes";
// remove the existing MenuItems one by one
for ( int n=MainMenu1->Items->Count-1; n>=1 ; n-- )
MainMenu1->Items->Items[n]->Free();
// Add the required (Sub)Menu Items one by one
MainMenu1->BeginUpdate();
TMenuItem* item = NewItem("&Table", NULL, false, true, Table1Click, 0, "Table1");
MainMenu1->Items->Insert(1,item);
item = NewItem("&Edit/View", NULL, false, true, EditView1Click, 0, "EditView1");
MainMenu1->Items->Insert(1,item);
item = NewItem("&Layers", NULL, false, true, NULL, 0, "Layers1");
TMenuItem* subitem = NewItem("&Add Layer", NULL, false, true, AddLayer1Click, 0, "AddLayer1");
item->Insert(0,subitem);
subitem = NewItem("&RemoveLayer", NULL, false, true, RemoveLayer1Click, 0, "RemoveLayer1");
item->Insert(1,subitem);
MainMenu1->Items->Insert(1,item);
MainMenu1->EndUpdate();
}
else
{
Mode1->Caption = "&Elements";
// remove the existing MenuItems one by one
for ( int n=MainMenu1->Items->Count-2; n>=1 ; n-- )
MainMenu1->Items->Items[n]->Free();
// build the other Menu thew same way.....
}
}
"Pietro" < XXXX@XXXXX.COM >wrote:
Quote
Hi!!!
I've a problem.
I've a MDIForm with 2 menu (1 empty and 1 full)
When the application start i charge the empty menu, after I show a login
form if
the user is logged correctly, i want to change the empty menu with the full
one.
How is possible??

Thank you in advance

Bye
Pietro


 

Re:Switch menu

On Wed, 11 Feb 2004 17:55:21 +0100, Pietro wrote:
Quote
How is possible??
Questions on using VCL components should be posted into
.vcl.components.using. This section is .ide and it's for questions relating
to the IDE (Editor, de{*word*81} etc).
--
Andrue Cope
[Bicester UK]
 

{smallsort}

Re:Switch menu

"Pietro" < XXXX@XXXXX.COM >wrote:
Quote
[...] How is possible??
Iterate through the 'real' menu's items. As you do, allocate
new menu items, assign the 'real' menu item's properties and
events to it and then use Add to add the newly allocated item
to the dummy menu.
When you allocate the new menu item, if you set it's owner to
the form, you don't have to worry about freeing the menu items
because when the form is destroyed, it's responsible for
cleaning up the objects that it owns. For example:
TMenuItem* pItem = new TMenuItem( this );
~ JD