BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

using menus several times

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Martin
Guest





PostPosted: Wed Jun 15, 2005 10:17 am    Post subject: using menus several times Reply with quote



Hello,

I am using a number of menus that shall appear as submenus in a main menu
and also as a popup menu for certain components. Now I want to avoid to have
all these menus double because their captions have all to be set at runtime
depending on the selected language.
So I built up the main menu as a normal component (TMainMenu) and wanted to
load one popup menu (TPopupMenu) at runtime with the menuitems depending on
the component right-clicked. Like this:

for (k = 0; k < Main_submenu->Count; k++)
PopupMenu1->Items->Add (Main_submenu->Items [k]);

It compiles, but the first time Add () is called I get an exception
EMenuError "Menu added two times" (I translated this back to english)

Is it possible at all what I want and how can I get it running?


Thank you very much for help

Martin


Back to top
Pete Fraser
Guest





PostPosted: Wed Jun 15, 2005 11:03 am    Post subject: Re: using menus several times Reply with quote



You are adding the same MenuItem onto different menus which is not allowed.
You need to create a new MenuItem instance and copy data from MainMenu onto
it and then add it to the PopupMenu1.

HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote

Quote:
Hello,

I am using a number of menus that shall appear as submenus in a main menu
and also as a popup menu for certain components. Now I want to avoid to
have all these menus double because their captions have all to be set at
runtime depending on the selected language.
So I built up the main menu as a normal component (TMainMenu) and wanted
to load one popup menu (TPopupMenu) at runtime with the menuitems
depending on the component right-clicked. Like this:

for (k = 0; k < Main_submenu->Count; k++)
PopupMenu1->Items->Add (Main_submenu->Items [k]);

It compiles, but the first time Add () is called I get an exception
EMenuError "Menu added two times" (I translated this back to english)

Is it possible at all what I want and how can I get it running?


Thank you very much for help

Martin




Back to top
Martin
Guest





PostPosted: Wed Jun 15, 2005 4:58 pm    Post subject: Re: using menus several times Reply with quote



Hello,

thank you for your help. It works like you said.
To be sure I would like to ask another question on this topic.
Now in the event handler OnPopup I first remove all items from the popup
menu with

PopupMenu1->Items->Clear ();

and then in a loop dynamically create new items (with new) and add them to
the menu.
Is it enough to just use Clear () to also completely remove the dynamically
created items from memory or do I need a corresponding delete for every new
I used?

Thank you again

Martin


Quote:
You are adding the same MenuItem onto different menus which is not
allowed.
You need to create a new MenuItem instance and copy data from MainMenu
onto it and then add it to the PopupMenu1.

HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote in message
news:42affffd (AT) newsgroups (DOT) borland.com...
Hello,

I am using a number of menus that shall appear as submenus in a main menu
and also as a popup menu for certain components. Now I want to avoid to
have all these menus double because their captions have all to be set at
runtime depending on the selected language.
So I built up the main menu as a normal component (TMainMenu) and wanted
to load one popup menu (TPopupMenu) at runtime with the menuitems
depending on the component right-clicked. Like this:

for (k = 0; k < Main_submenu->Count; k++)
PopupMenu1->Items->Add (Main_submenu->Items [k]);

It compiles, but the first time Add () is called I get an exception
EMenuError "Menu added two times" (I translated this back to english)

Is it possible at all what I want and how can I get it running?


Thank you very much for help

Martin








Back to top
Pete Fraser
Guest





PostPosted: Wed Jun 15, 2005 5:06 pm    Post subject: Re: using menus several times Reply with quote

Yes, clear() by itself is OK as all menu items are owned by the parent menu
and thus
deleted by it. The same is true for Forms etc.
HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote

Quote:
Hello,

thank you for your help. It works like you said.
To be sure I would like to ask another question on this topic.
Now in the event handler OnPopup I first remove all items from the popup
menu with

PopupMenu1->Items->Clear ();

and then in a loop dynamically create new items (with new) and add them to
the menu.
Is it enough to just use Clear () to also completely remove the
dynamically
created items from memory or do I need a corresponding delete for every
new
I used?

Thank you again

Martin


You are adding the same MenuItem onto different menus which is not
allowed.
You need to create a new MenuItem instance and copy data from MainMenu
onto it and then add it to the PopupMenu1.

HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote in message
news:42affffd (AT) newsgroups (DOT) borland.com...
Hello,

I am using a number of menus that shall appear as submenus in a main
menu
and also as a popup menu for certain components. Now I want to avoid to
have all these menus double because their captions have all to be set at
runtime depending on the selected language.
So I built up the main menu as a normal component (TMainMenu) and wanted
to load one popup menu (TPopupMenu) at runtime with the menuitems
depending on the component right-clicked. Like this:

for (k = 0; k < Main_submenu->Count; k++)
PopupMenu1->Items->Add (Main_submenu->Items [k]);

It compiles, but the first time Add () is called I get an exception
EMenuError "Menu added two times" (I translated this back to english)

Is it possible at all what I want and how can I get it running?


Thank you very much for help

Martin










Back to top
Martin
Guest





PostPosted: Wed Jun 15, 2005 7:17 pm    Post subject: Re: using menus several times Reply with quote

Hello Pete,

Thank you very much

Martin


Quote:
Yes, clear() by itself is OK as all menu items are owned by the parent
menu and thus
deleted by it. The same is true for Forms etc.
HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote in message
news:42b05dd9 (AT) newsgroups (DOT) borland.com...
Hello,

thank you for your help. It works like you said.
To be sure I would like to ask another question on this topic.
Now in the event handler OnPopup I first remove all items from the popup
menu with

PopupMenu1->Items->Clear ();

and then in a loop dynamically create new items (with new) and add them
to
the menu.
Is it enough to just use Clear () to also completely remove the
dynamically
created items from memory or do I need a corresponding delete for every
new
I used?

Thank you again

Martin


You are adding the same MenuItem onto different menus which is not
allowed.
You need to create a new MenuItem instance and copy data from MainMenu
onto it and then add it to the PopupMenu1.

HTH Pete

"Martin" <anonymous (AT) anonym (DOT) net> wrote in message
news:42affffd (AT) newsgroups (DOT) borland.com...
Hello,

I am using a number of menus that shall appear as submenus in a main
menu
and also as a popup menu for certain components. Now I want to avoid to
have all these menus double because their captions have all to be set
at
runtime depending on the selected language.
So I built up the main menu as a normal component (TMainMenu) and
wanted
to load one popup menu (TPopupMenu) at runtime with the menuitems
depending on the component right-clicked. Like this:

for (k = 0; k < Main_submenu->Count; k++)
PopupMenu1->Items->Add (Main_submenu->Items [k]);

It compiles, but the first time Add () is called I get an exception
EMenuError "Menu added two times" (I translated this back to english)

Is it possible at all what I want and how can I get it running?


Thank you very much for help

Martin












Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.