The Action List helps maintain order and consistency in the program's GUI during the design phase. Let's say you want to have:
- a main menu,
- toolbars (one or more),
- different context menus that are launched in different places.
The main menu (TMainMenu) usually has main sections (e.g. File, Edit, View, etc.). Each of these sections contains a list of menu items of type TMenuItem. Each of these menu items can have (for example):
- Caption (visible after the menu is displayed),
- Checked (the command can act as a Checkbox),
- GroupIndex (commands with the same numeric value create a set of switches acting as RadioButtons),
- Hint (a hint that can be displayed on the status bar),
- ImageIndex (the icon number from the image list connected to the TMainMenu object),
- RadioItem (the command can act as a RadioButton),
- ShortCut (the keyboard shortcut that starts this command),
- Visible.
In order for the TMenuItem command to trigger the execution of an action, you need to write an OnClick event handler. Context menus (TPopupMenu) are similar. Each of them has a list of items of type TMenuItem.
It's similar with toolbars (TToolBar). Each bar has a collection of buttons (TToolButton). Buttons also have similar properties to those listed above for TMenuItem (not all of them). To trigger an action after clicking a button, you also need to write an OnClick event handler.
The main menu, context menu, and toolbars can display icons (glyphs) next to their names. An image list (TImageList) is used for this purpose. When an image list is assigned to the main menu or toolbar, an image can be assigned to each menu item or button using its ImageIndex property.
Instead of programming the main menu, shortcut menus, and toolbar items separately, you can do this:
- place the TActionList on the form,
- create a list of actions using the action list editor,
- write OnExecute event handlers for each action,
- assign the list of images (TImageList) to the action list,
- set the image number (icon) for each action,
- finally assign individual actions to positions in the main menu and/or toolbars or context menus.
Menu items (TMenuItem) and toolbar buttons (TToolButton) have an Action property. This is used to assign an action to a menu item or button. Assigning an action to a menu item or toolbar button automatically assigns the appropriate properties (Caption, Hint, ImageIndex, etc.). This allows you to write event handlers once that perform specific operations in the program. I have been using this solution since it appeared in Delphi 4.