Naming the Menu Items

From RAD Studio
Jump to: navigation, search

Go Up to Building Menus


In contrast to the menu component itself, you need to explicitly name menu items as you add them to the form. You can do this in one of two ways:

  • Directly type the value for the Name property.
  • Type the value for the Caption property first, and let Delphi derive the Name property from the caption.

For example, if you give a menu item a Caption property value of File, Delphi assigns the menu item a Name property of File1. If you fill in the Name property before filling in the Caption property, Delphi leaves the Caption property blank until you type a value.

Note: If you enter characters in the Caption property that are not valid for Delphi identifiers, Delphi modifies the Name property accordingly. For example, if you want the caption to start with a number, Delphi precedes the number with a character to derive the Name property.

The following table demonstrates some examples of this, assuming all menu items shown appear in the same menu bar.

Sample captions and their derived names

Component caption Derived name Explanation

&File

File1

Removes ampersand

&File (2nd occurrence)

File2

Numerically orders duplicate items

1234

N12341

Adds a preceding letter and numerical order

1234 (2nd occurrence)

N12342

Adds a number to disambiguate the derived name

$@@@#

N1

Removes all non-standard characters, adding preceding letter and numerical order

- (hyphen)

N2

Numerical ordering of second occurrence of caption with no standard characters



As with the menu component, Delphi adds any menu item names to the form's type declaration, and those names then appear in the Component list.

See Also