views:

299

answers:

3

I have a main menu in an MDI parent form, and it as a main menu. Now I need to change the first level caption of my first menu item in runtime. How can I do that?

--- Update ---

Sorry. I forgot to tell you that the mainMenu is housed in a TcontrolBar. I think that is the problem because all answer so far don’t work. I had tried all that before. But this only occurs for the first level, all other levels change correctly.

+2  A: 

Perhaps I'm missing something, but it seems to be very simple:

MainMenu1.Items[0].Caption := '&Hello'; // first top-level item
MainMenu1.Items[1].Caption := '&World'; // second top-level item, etc.
TOndrej
+1  A: 

In the Menu Editor (at design time in the IDE), click on the menu you want to change, open the property inspector and change the name to something relevant, i.e MyFirstMenu.

Then in your code, whenever you want to change the menu items caption you can use:

MyFirstMenu.Caption := 'A New Caption';

or if the Main Menu is built dynamically see the answer TOndrej gave above.

[Edit1]

Do you mean you can set the caption successfully on the menu item but do not see the change on the TControlBar?

Aikislave
+1  A: 

If you are using the old technique of adding a TToolbar inside of a TControlBar, then adding a tool button for each top menu item, then what you see in the form as top level menu items are actually the tool buttons. Set their caption directly, and everything should work.

mghie