This forum is deprecated.
I'm porting an application from VCL to FMX. In VCL you can have a TMainMenu on more than one form. In FMX I add a menu to another form when there's already one on the main form and I get the error 'The main menu can be only a single instance'. I just wondered why is this? It's not mentioned on the help page for FMX.Menus.TMainMenu. I see that there is TMenuBar that I can use on the second form, but the style is a little different (the shadow for example). I could use TMenuBar on both forms, but why the need for TMainMenu at all then?
There are some other problems with using TMenuBar as well. Firstly, if I expand the first item and then move the cursor to the second item it doesn't expand the second item - I have to click again. This is not the expected behaviour of a menu. Secondly, I can insert a line break in a main menu by adding an item with a hyphen, but this doesn't show in a menu bar.
the FireMonkey framework works very different than VCL!
As the name itself say "MainMenu", then, really dont there shouldn't be another menu in the application!In FireMonkey, due to the hierarchy of objects and the possibility that any object (practically) can be a "container", therefore, it can easily have one object inside the other, it is not focused on the unit, but on the collection of objects in use !
Therefore, it would not make sense to have more than one "MainMenu" in the application.
Now, you can create an application in the "MDI" pattern, and thus have a "MainMenu" for the application, and, for each form you want to open, you can maintain this "MainMenu" with the desired options, that is, to add or exclude options that are not necessary in a specific form.
To avoid having to recreate the menu and sub-menu options, you can simply hide them (using the "Visible" property) according to the active form.
Another possibility would be to create all the menus and sub-menus of the application at the beginning, which would be nothing in performance, because no action would be performed beyond the definition of the MainMenu structure, including you could define the attributes of each menu, without problems.
Another possibility would be to create a "clone" of the current MainMenu, and then restore it when necessary.Remembering that to create another MainMenu, you need to "destroy" the previous one, and, as a result, you will destroy your entire item structure!
As FireMonkey is aimed at Cross-Platform programming and the use of DirectX graphics, a lot would be different from VCL components, which are basically based on MSWindows controls, encapsulated in many properties (procedure and functions) used by the IDE.
Im trying some technics about MainMenu and its use in more than one form!
Thanks for the reply. I understand that I could have all menu items in a single menu and then show / hide them depending on which form is visible, but how do I make the single instance of main menu appear on both forms (in Windows)? I understand that menus on Mac behave differently, which is I guess the main reason why only a single instance of TMainMenu is allowed.
Regarding your image, I know that the line break divider works in TMainMenu, but it doesn't work in TMenuBar, which is what I'm using for my second form currently.
Here using same way to TMainMenu or TMainBar components! Nothing different way!
Now, for each have your menu (in particular), I think that is possible, but DONT USING A TMAINMENU component because of your restrictions default!
You can simulate this using another components, like 2 TMenuBar