Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
DelphiVCL Documentation
Light Logo Dark Logo
DelphiVCL Documentation
  • Installation
  • Tutorials & Guides
    • Quickstart
    • Example Gallery
    • Frequently Asked Questions
  • Reference Manual
    • DelphiVCL
      • Object
      • StyleManager
      • Stream
      • Monitor
      • CustomStyleServices
      • Persistent
      • Strings
      • Picture
      • Collection
      • Canvas
      • Graphic
      • Bitmap
      • Icon
      • Metafile
      • Component
      • Timer
      • OpenDialog
      • MenuItem
      • Menu
      • FileOpenDialog
      • ContainedActionList
      • Control
      • CustomBindingsList
      • BasicBindComponent
      • BasicAction
      • BaseBindScopeComponent
      • BaseLinkingBindSource
      • ContainedAction
      • BindingsList
      • BoundLabel
      • CustomControl
      • Label
      • WinControl
      • CustomActionList
      • MainMenu
      • PopupMenu
      • SaveDialog
      • ActionList
      • MediaPlayer
      • CustomToggleSwitch
      • CustomActivityIndicator
      • CustomAction
      • Action
      • BaseObjectBindSource
      • CustomPrototypeBindSource
      • ActivityIndicator
      • ToggleSwitch
      • PrototypeBindSource
      • ContainedBindComponent
      • BindComponentDelegate
      • LinkPropertyToFieldDelegate
      • LinkControlDelegate
      • CustomLinkPropertyToField
      • LinkControlToFieldDelegate
      • LinkPropertyToField
      • CustomLinkControlToField
      • CustomLinkListControlToField
      • LinkControlToField
      • LinkListControlToField
      • BitBtn
      • Button
      • CheckBox
      • ColorBox
      • ComboBox
      • ControlBar
      • CustomGrid
      • CustomEdit
      • CustomForm
      • CustomStatusBar
      • CustomTabControl
      • DateTimePicker
      • GroupBox
      • Header
      • LabeledEdit
      • ListBox
      • Notebook
      • Page
      • PageControl
      • Panel
      • RadioButton
      • RadioGroup
      • ScrollBar
      • SpinButton
      • StaticText
      • TabSheet
      • ToolBar
      • TrackBar
      • CustomDrawGrid
      • CustomMemo
      • CustomNumberBox
      • Edit
      • SpinEdit
      • Form
      • StatusBar
      • TabControl
      • DrawGrid
      • Memo
      • NumberBox
      • StringGrid
      • CustomMemoryStream
      • HandleStream
      • MemoryStream
      • ResourceStream
      • FileStream
      • BytesStream
      • BufferedFileStream
      • StringStream
  • Changelog
    • v0.1.40
    • v1.0.0
    • v1.0.1
    • v1.0.2
    • v1.0.3
  • Contributing
Back to top

MenuItem¶

Qualified name: delphivcl.MenuItem

class MenuItem¶

Bases: Component

TMenuItem describes the properties of an item in a menu. Use TMenuItem to specify the appearance and behavior of an item in a menu. Each TMainMenu or TPopupMenu component can contain multiple menu items. When a menu is defined at design time, the Menu Designer automatically creates menu item objects for each command on the menu. The Caption property can be used to define an accelerator key to the menu item of a TMainMenu.

Methods

Add

TMenuItem.Add(Item: MenuItem) -> None Adds one or more menu items to the end of the Items property array.

BindMethodsToEvents

TComponent.BindMethodsToEvents(prefix) Connects methods to component events if they are named using the following pattern: Prefix_ComponentName_EventName.

Clear

Removes and frees all menu items listed in the Items property.

Click

Simulates a mouse click.

Delete

TMenuItem.Delete(Index: int) -> None Removes a menu item from the Items property array.

Find

TMenuItem.Find(ACaption: str) -> MenuItem Locates a menu item in the Items property array given its caption.

GetChildren

TMenuItem.GetChildren(Proc: Callable[[Component], None], Root: Component) -> None Enumerates all child components.

GetEnumerator

Returns a TComponent enumerator.

GetImageList

Returns the Image list that supplies an image for the menu item.

GetParentComponent

TComponent.GetParentComponent() Returns the parent of a component.

GetParentMenu

Returns the main menu of which the menu item is part.

HandleAllocated

TMenuItem.HandleAllocated() -> Boolean

HasParent

TComponent.HasParent() Indicates whether the component has a parent to handle its filing.

IndexOf

TMenuItem.IndexOf(Item: MenuItem) -> int Returns the position of a menu item within the Items array.

InitiateAction

Calls the action link's Update method if the menu item is associated with an action link.

Insert

TMenuItem.Insert(Index: int, Item: MenuItem) -> None Inserts a menu item into a specified position in the Items array.

InsertNewLineAfter

TMenuItem.InsertNewLineAfter(AItem: MenuItem) -> int Inserts a separator bar after a specified item from the Items property array.

InsertNewLineBefore

TMenuItem.InsertNewLineBefore(AItem: MenuItem) -> int Inserts a separator bar before a specified item from the Items property array.

IsLine

Indicates whether the menu item represents a separator bar.

NewBottomLine

Inserts a separator bar at the end of the Items property array.

NewTopLine

Inserts a separator bar at the beginning of the Items property array.

Remove

TMenuItem.Remove(Item: MenuItem) -> None Removes a menu item from the Items property array Call Remove to remove a menu item and all its submenus from a menu.

RethinkHotkeys

Adjusts the captions of subitems so that every item has an accelerator and there are no duplicate accelerator keys.

RethinkLines

Removes superfluous separator lines from the Items property array.

SetParentComponent

TMenuItem.SetParentComponent(Value: Component) -> None Sets the parent component.

Attributes

Action

Designates the action associated with the menu item.

AutoCheck

Indicates whether the menu item's checked state toggles automatically when the item is clicked.

AutoHotkeys

Determines whether the accelerator keys for submenu items can be reset automatically.

AutoLineReduction

Determines whether redundant separator bars are automatically removed from the submenu.

Bitmap

Designates a bitmap that is drawn for the menu item.

Break

Determines whether the menu item starts a new column in the menu.

Caption

Specifies the text of the menu item.

Checked

Specifies whether a check mark should appear beside the Caption.

ClassName

Returns the TObject.ClassName

ComObject

Specifies the interface reference implemented by the component.

Command

Specifies the Windows Command ID associated with the menu item.

ComponentCount

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.

Components

Returns an iterator over the owned components

Count

Indicates the number of subitems of the menu item.

Default

Specifies whether the menu item is invoked when the parent item is double clicked.

DesignInfo

Contains information used by the Form designer.

Enabled

Specifies whether the menu item is enabled.

GroupIndex

Identifies the logical group to which the menu item belongs.

Handle

Indicates the Windows menu handle of the drop-down menu associated with the menu item.

HelpContext

Specifies the help context ID associated with the menu item.

Hint

Specifies the text string that can appear when the user moves the mouse pointer over a menu item.

ImageIndex

Indicates which image maintained by the parent menu appears next to the menu item.

ImageName

Displays the name of linked items from the Image Collection.

Items

MenuItem:

MenuHandle

int:

MenuIndex

Indicates the index of the menu item within its parent menu.

Name

Specifies the name of the component as referenced in code.

Observers

Indicates the TObservers object added to the TComponent.

OnAdvancedDrawItem

Callable[[Object, Canvas, Rect, OwnerDrawState], None]:

OnDrawItem

Callable[[Object, Canvas, Rect, bool], None]:

OnMeasureItem

Callable[[Object, Canvas, int, int], None]:

Owner

Returns the Component Owner

Parent

Identifies the parent menu item of this menu item.

RadioItem

Specifies whether the menu item is mutually exclusive with other menu items in its group.

ShortCut

Shortcut that opens the menu item.

SubMenuImages

Lists the images that can appear beside individual items in a submenu of this menu item.

Tag

Stores a NativeInt integral value as a part of a component.

VCLComObject

Represents information used internally by components that support COM.

Visible

Specifies whether the menu item appears in the menu.

Action¶

Designates the action associated with the menu item. Action designates the action object that is associated with the menu item. Actions can be associated with a menu item by using the action list editor at design-time. Actions are a way of centralizing user responses to commands.

Type:

BasicAction

Add(Item: MenuItem) → None¶

Adds one or more menu items to the end of the Items property array. Use Add to add new menu items to the dropdown menu for this menu item. If this menu item is the value of the Items property of a main menu or pop-up menu, Add adds the items to the end of the menu. Specify a single new menu item to add as the value of the Item parameter, or an array of new menu items as the value of the AItems parameter. AItems_Size is the index of the last item in the AItems array (one less than the number of items). Adds one or more menu items to the end of the Items property array. Use Add to add new menu items to the dropdown menu for this menu item. If this menu item is the value of the Items property of a main menu or pop-up menu, Add adds the items to the end of the menu. Specify a single new menu item to add as the value of the Item parameter, or an array of new menu items as the value of the AItems parameter. AItems_Size is the index of the last item in the AItems array (one less than the number of items).

AutoCheck¶

Indicates whether the menu item’s checked state toggles automatically when the item is clicked. When AutoCheck is true, then every time the menu item is clicked, the value of the Checked property toggles automatically before the OnClick event occurs. When AutoCheck is false, the application must explicitly set the value of the Checked property (for example, in an OnClick event handler).

Type:

bool

AutoHotkeys¶

Determines whether the accelerator keys for submenu items can be reset automatically. Set AutoHotkeys to indicate whether the accelerator keys for the items in the Items property can be reset if necessary to ensure 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. TMenuItem 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, it checks and adjusts the accelerator key mappings if AutoHotkeys is maAutomatic or if AutoHotkeys is maParent and the parent menu item adjusts accelerator key mappings. Otherwise, the menu does not alter the items listed in the Items property, but may adjust the accelerator keys for submenus, depending on the AutoHotkeys property of the menu item that is the parent of the submenu.

Note: When AutoHotkeys disallows automatic adjustment of accelerator keys, an application can still adjust the menu items by calling the RethinkHotkeys method. AutoHotkeys merely controls whether this adjustment occurs automatically.

Type:

MenuItemAutoFlag

AutoLineReduction¶

Determines whether redundant separator bars are automatically removed from the submenu. Set AutoLineReduction to indicate whether the menu item should automatically ensure that the submenu defined by its Items property 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 run time do not have separator bars in undesired positions. Before the menu is displayed, the menu item removes superfluous separator bars if AutoLineReduction is maAutomatic or AutoLineReduction is maParent and the parent menu item removes superfluous separator bars. Otherwise, the menu item does not remove separators from the Items property, but may remove superfluous separators from submenus, depending on the AutoLineReduction property of the menu item that is the parent of the submenu.

Note: When AutoLineReduction disallows automatic removal of separator bars, an application can still remove superfluous separators by calling the RethinkLines method. AutoLineReduction merely controls whether this adjustment occurs automatically.

Type:

MenuItemAutoFlag

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_”.

Bitmap¶

Designates a bitmap that is drawn for the menu item. Use Bitmap to provide a custom image that appears next to the caption in the menu item. On owner-draw menus, Bitmap can be used from an OnDrawItem event handler to represent the entire menu item or a portion of the menu item.

Note: If the ImageIndex property is set and the parent menu has a non-nil (Delphi) or NULL (C++) Images property, the image identified by ImageIndex is used instead of Bitmap.

Type:

Bitmap

Break¶

Determines whether the menu item starts a new column in the menu. Set Break to break a long menu into columns at the item described by this menu item. The value of Break indicates whether the menu is broken into columns, and if so, whether a bar appears between the columns of the parent menu. The default is mbNone (no breaking into columns).

Type:

MenuBreak

Caption¶

Specifies the text of the menu item. Set Caption to the string the user sees for this item in the menu. To underline a character in a string, include an ampersand (&) before the character. This type of character is called an accelerator character. If Caption includes an accelerator character, the user can select the menu item by pressing Alt while typing the underlined character.

Tip: To automatically assign or adjust the accelerator characters in menu item captions, use the RethinkHotkeys method. Use the Caption property to identify the menu item as a line that separates the menu into parts. Specify a hyphen character (-) as the value of Caption for the menu item to indicate that the menu item is a separator. To separate the menu into multiple columns, use the Break property instead.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

str

Checked¶

Specifies whether a check mark should appear beside the Caption. Use Checked to allow a menu item to work like a check box. If Checked is true, the menu item appears checked. If Checked is false, the menu item remains unchecked.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

bool

Clear()¶

Removes and frees all menu items listed in the Items property. Use Clear to free all the items listed in the Items property array.

Click()¶

Simulates a mouse click. Click generates an OnClick event, as if the user had clicked the menu item. Unlike a real mouse click, Click does not generate a WM_COMMAND message to the window associated with the menu. Component writers can override click to provide a different response when the user selects the menu item.

Command¶

Specifies the Windows Command ID associated with the menu item. Use Command in an application that directly handles WM_COMMAND messages. When the user selects the menu item, Windows sends a WM_COMMAND to the window associated with the menu. The ItemID of the message contains the value of the Command property of the menu item that was selected.

Type:

int

ComponentCount¶

Returns the owned component count

Components¶

Returns an iterator over the owned components

Count¶

Indicates the number of subitems of the menu item. Read Count to determine the number of subitems listed in the Items property array. When the user clicks on a menu item that has subitems, a dropdown menu appears which displays those subitems. Each subitem can, in turn, contain additional subitems. The Count property counts only the immediate subitems of the menu item.

Type:

int

Default¶

Specifies whether the menu item is invoked when the parent item is double clicked. Set Default to specify whether a menu item is the default item in a submenu. Default menu items are executed when the parent item is double-clicked, allowing users to avoid navigating the submenus that contain them. The default item appears in boldface. A submenu can have only one default item. If the Items list of the parent menu item already contains a default menu item, setting the Default property to true sets the Default property of the previous default item to false.

Type:

bool

Delete(Index: int) → None¶

Removes a menu item from the Items property array. Call Delete to remove a menu item and all its submenus from a menu. The Index parameter is the index of the item to be deleted, where 0 specifies the first item in the menu, 1 specifies the second item, and so on. Delete does not free the removed item’s memory. To remove an item from the menu and free its memory, call the Free method in the item you want to remove. To temporarily hide a menu item, without deleting it, use the Visible property.

Enabled¶

Specifies whether the menu item is enabled. Use Enabled to enable or disable a menu item. If Enabled is true, the Click method is called when the user selects the item with the mouse. If Enabled is false, the menu item appears dimmed and the user cannot select it. However, calling the Click method works even when Enabled is false.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

bool

Find(ACaption: str) → MenuItem¶

Locates a menu item in the Items property array given its caption. Use Find to locate the menu item in the Items property array with the caption specified by the ACaption parameter. Find ignores accelerator characters when comparing item captions to the ACaption parameter. Find returns the first menu item in the Items property array with the specified caption. If no item is found, Find returns nil (Delphi) or NULL (C++).

GetChildren(Proc: Callable[[Component], None], Root: Component) → None¶

Enumerates all child components. Vcl.Menus.TMenuItem.GetChildren inherits from System.Classes.TComponent.GetChildren. All content below this line refers to System.Classes.TComponent.GetChildren. Enumerates all child components. GetChildren is used internally in the component streaming system. It is not necessary to call it directly. GetChildren expects a TGetChildProc routine that receives all enumerated components. Root represents the owner of the components that will be enumerated. This method does nothing in TComponent and is expected to be overridden in descendants.

GetEnumerator()¶

Returns a TComponent enumerator. Vcl.Menus.TMenuItem.GetEnumerator inherits from System.Classes.TComponent.GetEnumerator. All content below this line refers to System.Classes.TComponent.GetEnumerator. Returns a TComponent enumerator. GetEnumerator returns a TComponentEnumerator reference, which enumerates the components contained within a specified containing component. To process all these subcomponents, call the TComponentEnumerator GetCurrent method within a While MoveNext do loop.

GetImageList()¶

Returns the Image list that supplies an image for the menu item. Use GetImageList to access the list of images that contains the image for this menu item. The ImageIndex property identifies a specific image from the list that GetImageList returns. GetImageList first checks the Parent of this menu item for a SubMenuImages property. If the parent menu item does not maintain a list of images, it checks that menu item’s parent, and so on until reaching a top-level menu item (a menu item where Parent is not set). If none of the parent menu items has a SubMenuImages property, GetImageList checks the top-level menu for an Images property. GetImageList returns the first image list it finds. If it doesn’t find an image list, GetImageList returns nil (Delphi) or NULL (C++).

GetParentComponent()¶

Returns the parent of a component.

GetParentMenu()¶

Returns the main menu of which the menu item is part. GetParentMenu returns the menu that contains the menu item.

GroupIndex¶

Identifies the logical group to which the menu item belongs. Use GroupIndex to control how menus are merged. In applications that contain multiple forms, items from the menus of secondary forms can be merged into the application’s main menu as those forms become active. MDI applications always merge the menus of child windows with the main menu of the parent window. By default, all menu items in a menu bar (main menu) have the same GroupIndex value. To use GroupIndex to merge menus, set the GroupIndex value of each successive menu item to a value equal to or greater than that of the previous menu item. When a menu item in a menu bar that is merged into the application’s main menu has the same GroupIndex value as a menu item in the main menu, the menu item in the application’s main menu is replaced by the corresponding menu item. If multiple menu items in the application’s main menu have the same GroupIndex value, they can be replaced only by separate menu items from the other form’s menu that also have repeated GroupIndex values. Thus, the first main menu item with a given value is replaced by the first item in the second form with that value, the second item in the main form is replaced by the second item in the second form, and so on. When a menu item in a menu bar that is merged into the application’s main menu has a GroupIndex that falls between the GroupIndex values of two adjacent items on the application’s main menu, that menu item is inserted between the two adjacent items. If the item’s GroupIndex value is greater than all other GroupIndex values in the application’s main menu, the item appears at the end of the main menu. If the GroupIndex value is less than all other GroupIndex values in the application’s main menu, the menu item appears at the beginning of the main menu bar. When an object created by an OLE 2.0 server application is activated, the server can try to merge its menus with the menus of the container application. The GroupIndex property is used to replace up to three main menu items with items from the server, in the manner described above. The server application uses the following predefined GroupIndex values to locate menu items to replace:

Group

Index

Description

Edit

1

Server menu items for editing the active OLE object

View

3

Server menu items for modifying the view of the OLE object.

Help

5

Server menu items for accessing the server’s online Help.

Note: See the documentation for the OLE server for information about whether it attempts menu merge during in-place activation. GroupIndex can also be used to define groups of menu items that act like radio buttons. To allow menu items to behave like radio buttons, set the RadioItem property to all menu items in the group to true, and assign each menu item the same value of GroupIndex. Checking any menu item in the group will then uncheck the others.

Type:

int

Handle¶

Indicates the Windows menu handle of the drop-down menu associated with the menu item. Use Handle when calling a Windows API function that requires a menu handle. Handle is only valid if the Count property is greater than 0.

Type:

int

HandleAllocated() → Boolean¶
HasParent()¶

Indicates whether the component has a parent to handle its filing.

HelpContext¶

Specifies the help context ID associated with the menu item. Use HelpContext to associate the menu item with a screen in the Help system of the application. Each screen in the Help system should have a unique context ID. When a menu item is selected using the keyboard, pressing F1 displays a Help screen. Which Help screen appears depends on the value of the HelpContext property.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

int

Hint¶

Specifies the text string that can appear when the user moves the mouse pointer over a menu item. Set Hint to a string that provides more information about the meaning of the menu item than the Caption. The hint text appears in the Status Bar when the user pauses with the mouse over the menu item if Help Hints are enabled (that is, if the Form’s and the Application’s ShowHint properties are True). It is also available for the code in the application’s OnHint event handler. The value of Hint can specify both a short value for the Help Hint window and a longer string to be used by the OnHint event handler. To provide both a short and a long hint, set Hint to the short string, followed by a vertical bar (|), followed by the long string.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

str

ImageIndex¶

Indicates which image maintained by the parent menu appears next to the menu item. Set ImageIndex to designate an image that should appear next to the caption when the menu item is drawn. On top-level menu items, ImageIndex specifies a zero-offset index into the Images property of the parent menu (TMenu or TPopupMenu). On submenu items, ImageIndex is the zero-offset index into the parent item’s SubMenuImages property. If the parent menu or item does not maintain a list of images, use the Bitmap property to provide an image for a single menu item. However, any image specified by ImageIndex takes precedence over the Bitmap property. Bitmap is only used when ImageIndex has a negative value or the parent’s Images or SubMenuImages property is nil (Delphi) or NULL (C++).

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

int

ImageName¶

Displays the name of linked items from the Image Collection.

Type:

str

IndexOf(Item: MenuItem) → int¶

Returns the position of a menu item within the Items array. Call IndexOf to locate a menu item in the submenu headed by this menu item. IndexOf returns 0 for the first menu item, 1 for the second menu item, and so on. If the menu item is not in the submenu, IndexOf returns -1.

Note: IndexOf may not correspond to the position of the item in the menu the user sees if the menu includes some items that are not visible.

InitiateAction()¶

Calls the action link’s Update method if the menu item is associated with an action link. InitiateAction calls the action link, if there is one for the menu item, to update the association between the action and the menu item.

Insert(Index: int, Item: MenuItem) → None¶

Inserts a menu item into a specified position in the Items array. Use Insert to insert a new menu item to the dropdown menu for this menu item. If this menu item is the value of the Items property of a main menu or pop-up menu, Insert inserts an item into that menu. Specify the new menu item to add as the value of the Item parameter, and the position in the Items array as the value of the Index parameter.

InsertNewLineAfter(AItem: MenuItem) → int¶

Inserts a separator bar after a specified item from the Items property array. Use InsertNewLineAfter to insert a separator bar after the menu item specified by AItem. If AItem is not an item in the Items property array, InsertNewLineAfter raises an exception. InsertNewLineAfter returns the index of the newly inserted separator item in the Items property array.

Tip: When inserting separator bars at runtime, it is a good idea to set AutoLineReduction to true so that superfluous separators can be automatically removed.

InsertNewLineBefore(AItem: MenuItem) → int¶

Inserts a separator bar before a specified item from the Items property array. Use InsertNewLineBefore to insert a separator bar before the menu item specified by AItem. If AItem is not an item in the Items property array, InsertNewLineBefore raises an exception. InsertNewLineBefore returns the index of the newly inserted separator item in the Items property array.

Tip: When inserting separator bars at runtime, it is a good idea to set AutoLineReduction to true so that superfluous separators can be automatically removed.

IsLine()¶

Indicates whether the menu item represents a separator bar. Call IsLine to determine whether the menu item is a separator bar. IsLine checks the Caption of the menu item and returns true if the value of Caption is ‘-’. Menu items with this Caption appear as separator bars.

Items¶

MenuItem:

MenuHandle¶

int:

MenuIndex¶

Indicates the index of the menu item within its parent menu. Use MenuIndex to locate the menu item in the Items property of its parent menu item. Changing this value moves the menu item within its menu.

Note: MenuIndex may not correspond to the position of the item in the menu the user sees. The menu can include items that are not visible.

Type:

int

NewBottomLine()¶

Inserts a separator bar at the end of the Items property array. Use NewBottomLine to insert a separator bar at the end of the items property array. This is useful when building up submenus dynamically at runtime. NewBottomLine returns the index of the newly inserted separator item in the Items property array.

Tip: When inserting separator bars at runtime, it is a good idea to set AutoLineReduction to true so that superfluous separators can be automatically removed.

NewTopLine()¶

Inserts a separator bar at the beginning of the Items property array. Use NewTopLine to insert a separator bar at the beginning of the items property array. This is useful when building up submenus dynamically at runtime. NewTopLine returns the index of the newly inserted separator item in the Items property array.

Tip: When inserting separator bars at runtime, it is a good idea to set AutoLineReduction to true so that superfluous separators can be automatically removed.

OnAdvancedDrawItem¶

Callable[[Object, Canvas, Rect, OwnerDrawState], None]:

OnDrawItem¶

Callable[[Object, Canvas, Rect, bool], None]:

OnMeasureItem¶

Callable[[Object, Canvas, int, int], None]:

Owner¶

Returns the Component Owner

Parent¶

Identifies the parent menu item of this menu item. Read Parent to determine the menu item that represents the dropdown menu that contains this menu item. If the menu item is a top level menu item in a main menu or pop-up menu, Parent is the value of that menu’s Items property.

Type:

MenuItem

RadioItem¶

Specifies whether the menu item is mutually exclusive with other menu items in its group. Use RadioItem to make the menu item behave like a radio button with a group of other menu items. The group of menu items is the set of all menu items in a pop-up or drop-down menu that have the same value of GroupIndex. When RadioItem is true, only one menu item in the group that contains the menu item can be checked at a time. The single selected menu item in the group is indicated by a round dot next to the Caption.

Note: RadioItem does not automatically select the item when the user clicks it at runtime: you must still explicitly set the Checked property to true in response to the OnClick event. RadioItem simply changes the appearance of the Checked state (from a check mark to a round dot) and automatically unchecks other menu items in the same group when you set the Checked property to true. RadioItem does not work for the top-level items in a main menu.

Note: Under Windows NT 3.51, the round dot indicator only appears if the “new shell” has been installed.

Type:

bool

Remove(Item: MenuItem) → None¶

Removes a menu item from the Items property array Call Remove to remove a menu item and all its submenus from a menu. The Item parameter is the item to be removed. If Item is not a menu item in the Items array, Remove raises an exception. Remove does not free the item’s memory. To remove an item from the menu and free its memory, call the Free method in the item you want to remove. To temporarily hide a menu item, without deleting it, use the Visible property.

RethinkHotkeys()¶

Adjusts the captions of subitems so that every item has an accelerator and there are no duplicate accelerator keys. Call RethinkHotkeys to adjust the accelerator keys for the items in the Items property and in any submenu of those items. RethinkHotkeys checks for items that do not have an accelerator key or that have duplicate accelerator keys. It then replaces any duplicate accelerators with unique characters and adds accelerator keys to items that don’t have them. RethinkHotkeys gives first priority to existing accelerator key mappings, but may change them if necessary to ensure uniqueness. RethinkHotkeys lets a menu adjust the accelerator keys when the AutoHotkeys property is false. For any menu or submenu that has AutoHotkeys set to true, this adjustment occurs automatically. RethinkHotkeys returns true if RethinkHotkeys changed the Caption property of any menu items, false otherwise.

RethinkLines()¶

Removes superfluous separator lines from the Items property array. Call RethinkLines to remove superfluous separators from the items in the Items property and in any submenu of those items. RethinkLines removes separators that appear at the very beginning or end of a submenu and separators that immediately follow another separator. RethinkLines lets a menu remove superfluous separators when the AutoLineReduction property is false. For any menu or submenu that has AutoLineReduction set to true, this adjustment occurs automatically. RethinkLines returns true if RethinkLines removed any menu items, false otherwise.

SetParentComponent(Value: Component) → None¶

Sets the parent component. Vcl.Menus.TMenuItem.SetParentComponent inherits from System.Classes.TComponent.SetParentComponent. All content below this line refers to System.Classes.TComponent.SetParentComponent. Sets the parent component. SetParentComponent is used internally in the component streaming system. It is not necessary to call it directly. Derived classes override this method to implement proper handling for parenting.

ShortCut¶

Shortcut that opens the menu item. The string representation of this shortcut appears to the right of the menu item in the menu.

Note: ShortCut is not stored with the menu item if it is supplied by an action.

Type:

int

SubMenuImages¶

Lists the images that can appear beside individual items in a submenu of this menu item. Use SubMenuImages to supply a set of images that can appear beside items listed in the Items property. Individual menu items set their ImageIndex property to indicate which image in the list appears to the left of the menu item caption.

Tip: If the application uses action lists, this property can be the value of the command list’s Images property. This way, menu items and buttons that do the same thing can display the same image.

Type:

CustomImageList

Visible¶

Specifies whether the menu item appears in the menu. Use Visible to prevent the user from seeing an item in the menu. For example, remove menu items that do not apply to the current component of a pop-up menu in an OnPopup event handler. If Visible is true, the menu item appears. If Visible is false, the menu item is hidden.

Note: This property is not stored with the menu item if it is supplied by a TAction object.

Type:

bool

Next
Menu
Previous
OpenDialog
Copyright © 2020-2023, Embarcadero Python Dev Team
Made with Sphinx and @pradyunsg's Furo
On this page
  • MenuItem
    • MenuItem
      • MenuItem.Action
      • MenuItem.Add()
      • MenuItem.AutoCheck
      • MenuItem.AutoHotkeys
      • MenuItem.AutoLineReduction
      • MenuItem.BindMethodsToEvents()
      • MenuItem.Bitmap
      • MenuItem.Break
      • MenuItem.Caption
      • MenuItem.Checked
      • MenuItem.Clear()
      • MenuItem.Click()
      • MenuItem.Command
      • MenuItem.ComponentCount
      • MenuItem.Components
      • MenuItem.Count
      • MenuItem.Default
      • MenuItem.Delete()
      • MenuItem.Enabled
      • MenuItem.Find()
      • MenuItem.GetChildren()
      • MenuItem.GetEnumerator()
      • MenuItem.GetImageList()
      • MenuItem.GetParentComponent()
      • MenuItem.GetParentMenu()
      • MenuItem.GroupIndex
      • MenuItem.Handle
      • MenuItem.HandleAllocated()
      • MenuItem.HasParent()
      • MenuItem.HelpContext
      • MenuItem.Hint
      • MenuItem.ImageIndex
      • MenuItem.ImageName
      • MenuItem.IndexOf()
      • MenuItem.InitiateAction()
      • MenuItem.Insert()
      • MenuItem.InsertNewLineAfter()
      • MenuItem.InsertNewLineBefore()
      • MenuItem.IsLine()
      • MenuItem.Items
      • MenuItem.MenuHandle
      • MenuItem.MenuIndex
      • MenuItem.NewBottomLine()
      • MenuItem.NewTopLine()
      • MenuItem.OnAdvancedDrawItem
      • MenuItem.OnDrawItem
      • MenuItem.OnMeasureItem
      • MenuItem.Owner
      • MenuItem.Parent
      • MenuItem.RadioItem
      • MenuItem.Remove()
      • MenuItem.RethinkHotkeys()
      • MenuItem.RethinkLines()
      • MenuItem.SetParentComponent()
      • MenuItem.ShortCut
      • MenuItem.SubMenuImages
      • MenuItem.Visible