Using Menus in a FireMonkey Application

From RAD Studio
Jump to: navigation, search

Go Up to FireMonkey Application Design

FireMonkey supports both lightweight styled menus displayed on the form, and native menus.

Drop-Down Menus

Traditional desktop-OS drop-down menus are hosted in a TMenuBar, a fully styled control. It acts as the root of a tree of TMenuItem objects. The first generation of children are visible in the menu bar. Second generation items are displayed under their parent when the parent item is clicked. Later generations are displayed as sub-menus to the right.

Menu items have label Text and an optional Bitmap image. Items can be checked through the IsChecked trigger property. Setting AutoCheck to True will automatically toggle IsChecked every time the item is clicked. A group of menu items can be designated so that only one item at most is checked, by setting RadioItem to True on each item, and GroupIndex to the same arbitrary value.

Implement menu actions in the OnClick event handler. Assign the code representation of a shortcut to the ShortCut property for shortcut keys.

To create a menu separator item, set the Text to a single hyphen-minus character (Unicode code point U+002D, ASCII 45).

Creating Menus for macOS and Windows

Use the correct control for your target system (macOS vs. Windows).

  • For Windows applications, use the TMenuBar control:
    • The main menu is placed in the client area of the form (standard for Windows).
    • The menu items are not on the macOS menu bar (nonstandard for macOS).
  • For macOS applications, use the TMainMenu component:
    • The main menu is placed in the non-client area of the Windows form (nonstandard for Windows).
    • Menu items are placed on the macOS menu bar (standard for macOS).
    • In the macOS application, in the Application Menu, system menu items are added automatically.
    • Other items can be added to the Application Menu using subitems of the first visible main menu item in TMainMenu. These items will appear above the Services system menu item. If the first visible main menu item is intended for subitems of the Application menu, this item should be hidden for platforms other than macOS.

Using Keyboard Shortcuts

To activate menu commands you can assign keyboard shortcuts in the ShortCut property of the menu item of a TMainMenu.


See Also