RAD Studio
ContentsIndex
PreviousUpNext
Creating Toolbars and Menus

Note: This topic describes the recommended method for creating menus and toolbars in Windows applications. For cross-platform development, you need to use TToolBar and the menu components, such as TMainMenu, organizing them using action lists (TActionList). See Setting up action lists for details.
You use the Action Manager to automatically generate toolbars and main menus based on the actions contained in your application. The Action Manager manages standard actions and any custom actions that you have written. You then create UI elements based on these actions and use action bands to render the actions items as either menu items or as buttons on a toolbar. 

The general procedure for creating menus, toolbars, and other action bands involves these steps:

  • Drop an Action Manager onto a form.
  • Add actions to the Action Manager, which organizes them into appropriate action lists.
  • Create the action bands (that is, the menu or the toolbar) for the user interface.
  • Drag and drop the actions into the application interface.
The following procedure explains these steps in more detail.

To create menus and toolbars using action bands:

  1. From the Additional category of the Tool palette, drop an Action Manager component (TActionManager) onto the form where you want to create the toolbar or menu.
  2. If you want images on the menu or toolbar, drop an ImageList component from the Win32 category of the Tool palette onto a form. (You need to add the images you want to use to the ImageList or use the one provided.)
  3. From the Additional category of the Tool palette, drop one or more of the following action bands onto the form:
    • TCustomActionMainMenuBar(for designing main menus)
    • TActionToolBar(for designing toolbars)
  4. Connect the ImageList to the Action Manager: with focus on the Action Manager and in the Object Inspector, select the name of the ImageList from the Images property.
  5. Add actions to the Action Manager editor's action pane:
    • Double-click the Action Manager to display the Action Manager editor.
    • Click the drop-down arrow next to the New Action button (the leftmost button at the top right corner of the Actions tab) and select New Action or New Standard Action. A tree view is displayed. Add one or more actions or categories of actions to the Action Manager's actions pane. The Action Manager adds the actions to its action lists.
  6. Drag and drop single actions or categories of actions from the Action Manager editor onto the menu or toolbar you are designing.
To add user-defined actions, create a new TAction by pressing the New Action button and writing an event handler that defines how it will respond when fired. See What happens when an action fires for details. Once you've defined the actions, you can drag and drop them onto menus or toolbars like the standard actions.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!