Menu¶
Qualified name: delphivcl.Menu
- class Menu¶
Bases:
Component
TMenu is the base type for menu components such as TMainMenu and TPopupMenu. Use TMenu as a base class when defining a component that represents a collection of menu items. TMenu introduces properties and methods to create a Windows menu that represents a set of menu items, dispatch commands associated with those menu items, and locate the help context id for any of those menu items.
Methods
Connects methods to component events if they are named using the following pattern: Prefix_ComponentName_EventName.
Embarcadero Technologies does not currently have any additional information.
Calls the Click method of the menu item with the specified value as its Command property.
Dispatches a pop-up menu command.
Locates and returns a menu item.
Executes a callback for child menu items.
Returns the help context ID associated with a menu item.
Returns the parent of a component.
Indicates whether the component has a parent to handle its filing.
Indicates whether menu items read from right to left.
Dispatches a key message if it represents a shortcut key for an item in the menu.
Ensures that the menu's layout follows the current settings of the BiDiMode and ParentBiDiMode properties.
Responds to keyboard input for the menu.
Attributes
Determines whether the accelerator keys for menu items can be reset automatically.
Determines whether redundant separator bars are automatically removed from the menu.
Determines the layout of the menu in Middle East locales.
ClassName
Returns the TObject.ClassName
ComObject
Specifies the interface reference implemented by the component.
Returns the owned component count
ComponentIndex
Indicates the position of the component in its owner's Components property array.
ComponentState
Describes the current state of the component, indicating when a component needs to avoid certain actions.
ComponentStyle
Governs the behavior of the component.
Returns an iterator over the owned components
DesignInfo
Contains information used by the Form designer.
Provides access to the Windows menu handle for the menu.
Lists the images that can appear beside individual menu items.
Describes the elements of the menu.
Name
Specifies the name of the component as referenced in code.
Observers
Indicates the TObservers object added to the TComponent.
Returns the Component Owner
Specifies whether the menu items are drawn by the application.
Indicates whether the BiDiMode property is inherited from the control that uses the menu.
Tag
Stores a NativeInt integral value as a part of a component.
VCLComObject
Represents information used internally by components that support COM.
Provides access to the handle of the window that uses the menu.
- AutoHotkeys¶
Determines whether the accelerator keys for menu items can be reset automatically. Set AutoHotkeys to indicate whether the menu should automatically ensure that accelerator keys for its items are reset if necessary so that every menu item has an accelerator key and no two items have the same accelerator key. This ensures that menu items added dynamically at runtime can have accelerator keys that do not introduce conflicts. TMenu tries to preserve all existing accelerator key mappings when adjusting the accelerator keys, but may be forced to change some in order to ensure that every item has a unique accelerator. Before the menu is displayed, the menu checks and adjusts the accelerator key mappings if AutoHotkeys is maAutomatic. When AutoHotkeys is maManual, the menu does not alter the top-level menu items, but may adjust the accelerator keys for submenus, depending on the AutoHotkeys property of the menu item that is the parent of the submenu. When AutoHotkeys is maManual, an application can still adjust the menu items by calling the Items property’s RethinkHotkeys method. AutoHotkeys merely controls whether this adjustment occurs automatically.
Note: The AutoHotkeys property of a menu is linked to the AutoHotkeys property of the TMenuItems object that implements its Items property. Setting one sets the other.
- Type:
MenuAutoFlag
- AutoLineReduction¶
Determines whether redundant separator bars are automatically removed from the menu. Set AutoLineReduction to indicate whether the menu should automatically ensure that the menu does not start or end with a separator bar and that two separator bars do not appear next to each other. This ensures that menus built dynamically at runtime do not have separator bars in undesired positions. Before the menu is displayed, it removes superfluous separator bars when AutoLineReduction is maAutomatic. When AutoLineReduction is maManual, the menu does not remove separators from the top-level menu items, but may remove superfluous separators from submenus, depending on the AutoLineReduction property of the menu item that is the parent of the submenu. When AutoLineReduction is maManual, an application can still remove superfluous separators by calling the Items property’s RethinkLines method. AutoLineReduction merely determines whether this adjustment occurs automatically.
Note: The AutoLineReduction property of a menu is linked to the AutoLineReduction property of the TMenuItems object that implements its Items property. Setting one sets the other.
- Type:
MenuAutoFlag
- BiDiMode¶
Determines the layout of the menu in Middle East locales. Set BiDiMode to control the layout of menu items. BiDiMode controls whether the menu items read from left to right or right to left.
- Type:
BiDiMode
- BindMethodsToEvents(prefix)¶
Connects methods to component events if they are named using the following pattern: Prefix_ComponentName_EventName. Example: def handle_button1_OnClick(Sender): pass The function returns a list of tuples. Each tuple contains the name of the component, the name of the event and the method object assigned to the event. Note that the prefix parameter is optional and will default to “handle_”.
- ComponentCount¶
Returns the owned component count
- Components¶
Returns an iterator over the owned components
- CreateMenuItem()¶
Embarcadero Technologies does not currently have any additional information.
- DispatchCommand(ACommand: int) → bool¶
Calls the Click method of the menu item with the specified value as its Command property. Call DispatchCommand to simulate a click on the menu item associated with a command ID. If DispatchCommand locates a menu item that matches the command ID, it calls the Click method for that menu item and returns true. If there is no such item, DispatchCommand returns false.
- DispatchPopup(AHandle: int) → bool¶
Dispatches a pop-up menu command. Call DispatchPopup to simulate a click on the menu item associated with the pop-up menu handle. If DispatchPopup locates a menu item that matches the pop-up menu handle, it calls the Click method for that menu item and returns true. If there is no such item, DispatchPopup returns false.
- FindItem(Value: int, Kind: FindItemKind) → MenuItem¶
Locates and returns a menu item. Call FindItem to locate a menu item in the menu or one of its submenus. The menu item is identified by either a pop-up menu handle, command ID, or menu shortcut value. The Kind parameter specifies how the menu item is to be identified.
- GetChildren(Proc: Callable[[Component], None], Root: Component) → None¶
Executes a callback for child menu items. GetChildren is called automatically by the streaming system so that child menu items are saved and read with their parent menu.
- GetHelpContext(Value: int, ByCommand: bool) → int¶
Returns the help context ID associated with a menu item. Call GetHelpContext to obtain the ID for context-sensitive help on a particular menu item. Identify the menu item as the item that matches the Value property. If ByCommand is true, Value is the Command property of the TMenuItem. If ByCommand is false, Value is the Handle property.
- GetParentComponent()¶
Returns the parent of a component.
- Handle¶
Provides access to the Windows menu handle for the menu. Use Handle to call a Windows API function that requires a menu handle. Handle is the handle for the menu that contains only the items described by the Items property.
- Type:
int
- HasParent()¶
Indicates whether the component has a parent to handle its filing.
- Images¶
Lists the images that can appear beside individual menu items. Use Images to hold the set of images that can appear beside menu items in the menu. Individual menu items set their ImageIndex property to indicate which image in the list appears to the left of the menu item caption. Images in the list should be 16x16.
Tip: If the application uses action lists, this property should be the value of the action list’s Images property. This way, menu items and buttons that do the same thing can display the same image.
- Type:
CustomImageList
- IsRightToLeft()¶
Indicates whether menu items read from right to left. Call IsRightToLeft to determine the layout of main menu items. IsRightToLeft returns true if the application is running on a system with a Middle Eastern locale and the BiDiMode property is not bdLeftToRight.
- IsShortCut(Message: WMKey) → bool¶
Dispatches a key message if it represents a shortcut key for an item in the menu. Call IsShortCut when processing a KeyDown message to identify shortcut keys and trigger the appropriate menu action. IsShortCut decodes the key message passed in the Message parameter. It then encodes the state of the Shift, Control, and Alt keys with the value of the character that was typed to obtain the ShortCut property of a menu item. If IsShortCut locates a menu item associated with the shortcut key combination, it calls the item’s Click method and returns true. If no item in the menu has a shortcut corresponding to the message, IsShortCut returns false.
- Items¶
Describes the elements of the menu. Use Items to access information about the elements in the menu. Items is a single TMenuItem object that describes the elements of the menu in its own Items property.
Note: Because Items is the default property of TMenuItem, the Items property of TMenu can be treated as an indexed array of menu items that describe the individual items in the menu. That is, instead of writing Note: FirstItem�:= Menu1.Items.Items[0]; Note: you can use Note: FirstItem�:= Menu1.Items[0]; Set the Items property at design time by clicking on the Items property in the Property Inspector. The Menu Designer automatically inserts a menu item. As each menu item is entered, outlined regions appear at the possible locations of additional menu items. Click in those regions to specify additional menu items. At runtime, create a TMenuItem that describes the elements of the menu programmatically, and set the Items property of the menu.
- Type:
- Owner¶
Returns the Component Owner
- OwnerDraw¶
Specifies whether the menu items are drawn by the application. Set OwnerDraw to true to indicate that the application will draw menu items in an OnDrawItem event handler. When OwnerDraw is true, menu items receive an OnMeasureItem and an OnDrawItem event when they need to be rendered on screen. Set OwnerDraw to false to accept the default drawing. When OwnerDraw is false, menu items display the caption with an optional image to the left (If the Images and ImageIndex properties are set). Owner-draw menus are useful for displaying the value that appears when selecting a menu item. For example, in a menu that allows users to choose a color, an owner-draw menu could display rectangles drawn in the designated color, rather than color names.
- Type:
bool
- ParentBiDiMode¶
Indicates whether the BiDiMode property is inherited from the control that uses the menu. By default, ParentBiDiMode is true, indicating that the layout of menu items follows the BiDiMode setting of the associated form or control. Change ParentBiDiMode to false to override the default BiDiMode setting and control the menu’s layout independently.
- Type:
bool
- ParentBiDiModeChanged()¶
Ensures that the menu’s layout follows the current settings of the BiDiMode and ParentBiDiMode properties. ParentBiDiMode changed is called when the menu’s BiDiMode property must be updated to reflect the bi-directional mode of its associated control. Ensures that the menu’s layout follows the current settings of the BiDiMode and ParentBiDiMode properties. ParentBiDiMode changed is called when the menu’s BiDiMode property must be updated to reflect the bi-directional mode of its associated control.
- ProcessMenuChar(Message: WMMenuChar) → None¶
Responds to keyboard input for the menu. ProcessMenuChar handles keyboard messages from Windows. It checks whether the character typed is an accelerator character from one of the menu’s items. If so, ProcessMenuChar executes the menu item (or, if the item is disabled, selects it). If the key is not an accelerator, ProcessMenuChar checks for captions that begin with the character. If there is only one, it is treated like an accelerator. Otherwise, the first item beginning with that character is selected. When calling ProcessMenuChar programmatically, the User, MenuFlag, and Menu fields of Message parameter must be supplied.
- WindowHandle¶
Provides access to the handle of the window that uses the menu. Read WindowHandle to get the window handle of the control that receives WM_COMMAND messages when the user clicks on an item in the menu. When menu items are selected, use this handle in an OnClick event handler to send messages to the control that uses the menu or to make Windows API calls that affect the control. Set WindowHandle to associate the menu with a control.
- Type:
int