RAD Studio |  |

Associating Menu Events with Event Handlers
See Also
Collapse All

The Menu Designer, along with the MainMenu and PopupMenu components, make it easy to supply your application with drop-down and pop-up menus. For the menus to work, however, each menu item must respond to the OnClick event, which occurs whenever the user chooses the menu item or presses its accelerator or shortcut key. This topic explains how to associate event handlers with menu items. For information about the Menu Designer and related components, see Creating and managing menus.

To create an event handler for a menu item:

1. Open the Menu Designer by double-clicking on a MainMenu or PopupMenu component.
2. Select a menu item in the Menu Designer. In the Object Inspector, make sure that a value is assigned to the item's Name property.
3. From the Menu Designer, double-click the menu item. The Code editor opens with the cursor inside the skeleton event handler, or the begin...end block.
4. At the cursor, type the code that you want to execute when the user selects the menu command.

To associate a menu item with an existing OnClick event handler:

1. Open the Menu Designer by double-clicking a MainMenu or PopupMenu component.
2. Select a menu item in the Menu Designer. In the Object Inspector, make sure that a value is assigned to the item's Name property.
3. On the Events page of the Object Inspector, click the down arrow in the Value column next to OnClick to open a list of previously written event handlers. (The list includes only event handlers written for OnClick events on this form.) Select from the list by clicking an event handler name.

See Also

Working with Events and Event Handlers

Deleting Event Handlers

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