Sign in Join
FPDoc Onlineexperiment

NewSubMenu function

In unit Menus

Creates and configures a new sub-menu with the specified child menu items.

Declaration

pascal
function NewSubMenu(const ACaption: string; hCtx: THelpContext; 
 const AName: string; 
 const Items: Array of TMenuItem = class(TLCLComponent)
private
 FActionLink: TMenuActionLink;
 FAutoLineReduction: TMenuItemAutoFlag;
 FCaption: TTranslateString;
 FBitmap: TBitmap;
 FGlyphShowMode: TGlyphShowMode;
 FHandle: HMENU;
 FHelpContext: THelpContext;
 FHint: TTranslateString;
 FImageChangeLink: TChangeLink;
 FImageIndex: TImageIndex;
 FItems: TList;
 FMenu: TMenu;
 FOnChange: TMenuChangeEvent;
 FOnClick: TNotifyEvent;
 FOnDrawItem: TMenuDrawItemEvent;
 FOnMeasureItem: TMenuMeasureItemEvent;
 FParent: TMenuItem;
 FMerged: TMenuItem;
 FMergedWith: TMenuItem;
 FMergedItems: TMergedMenuItems;
 FMenuItemHandlers: Array[TMenuItemHandlerType] of TMethodList = LazMethodList.TMethodList;
 FSubMenuImages: TCustomImageList;
 FSubMenuImagesWidth: Integer;
 FShortCut: TShortCut;
 FShortCutKey2: TShortCut;
 FGroupIndex: Byte;
 FRadioItem: Boolean;
 FRightJustify: Boolean;
 FShowAlwaysCheckable: Boolean;
 FVisible: Boolean;
 FBitmapIsValid: Boolean;
 FAutoCheck: Boolean;
 FChecked: Boolean;
 FDefault: Boolean;
 FEnabled: Boolean;
 function GetBitmap: TBitmap;
 function GetCount: Integer;
 function GetItem(Index: Integer): TMenuItem;
 function GetMenuIndex: Integer;
 function GetMergedItems: TMergedMenuItems;
 function GetMergedParent: TMenuItem;
 function GetParent: TMenuItem;
 function IsBitmapStored: Boolean;
 function IsCaptionStored: Boolean;
 function IsCheckedStored: Boolean;
 function IsEnabledStored: Boolean;
 function IsHelpContextStored: Boolean;
 function IsHintStored: Boolean;
 function IsImageIndexStored: Boolean;
 function IsShortCutStored: Boolean;
 function IsVisibleStored: Boolean;
 procedure MergeWith(const aMenu: TMenuItem);
 procedure SetAutoCheck(const AValue: Boolean);
 procedure SetAutoLineReduction(AValue: TMenuItemAutoFlag);
 procedure SetCaption(const AValue: TTranslateString);
 procedure SetChecked(AValue: Boolean);
 procedure SetDefault(AValue: Boolean);
 procedure SetEnabled(AValue: Boolean);
 procedure SetBitmap(const AValue: TBitmap);
 procedure SetGlyphShowMode(const AValue: TGlyphShowMode);
 procedure SetMenuIndex(AValue: Integer);
 procedure SetName(const Value: TComponentName); override;
 procedure SetRadioItem(const AValue: Boolean);
 procedure SetRightJustify(const AValue: Boolean);
 procedure SetShowAlwaysCheckable(const AValue: Boolean);
 procedure SetSubMenuImages(const AValue: TCustomImageList);
 procedure SetSubMenuImagesWidth(const aSubMenuImagesWidth: Integer);
 procedure ShortcutChanged;
 procedure SubItemChanged(Sender: TObject; Source: TMenuItem; 
 Rebuild: Boolean);
 procedure TurnSiblingsOff;
 procedure DoActionChange(Sender: TObject);
protected
 FCommand: Word;
 class procedure WSRegisterClass; override;
 procedure ActionChange(Sender: TObject; CheckDefaults: Boolean)
 ; virtual;
 procedure AssignTo(Dest: TPersistent); override;
 function GetAutoLineReduction: Boolean;
 procedure BitmapChange(Sender: TObject);
 function DoDrawItem(ACanvas: TCanvas; ARect: TRect; 
 AState: TOwnerDrawState): Boolean; virtual;
 function DoMeasureItem(ACanvas: TCanvas; var AWidth: Integer; 
 var AHeight: Integer): Boolean; virtual;
 function InternalRethinkLines(AForced: Boolean): Boolean; virtual;
 function GetAction: TBasicAction;
 function GetActionLinkClass: TMenuActionLinkClass; virtual;
 function GetHandle: HMENU;
 procedure DoClicked(var msg); message;
 procedure CheckChildrenHandles;
 procedure CreateHandle; virtual;
 procedure DestroyHandle; virtual;
 procedure Loaded; override;
 procedure Notification(AComponent: TComponent; Operation: TOperation)
 ; override;
 procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
 procedure InitiateActions;
 procedure MenuChanged(Rebuild: Boolean);
 procedure SetAction(NewAction: TBasicAction);
 procedure SetChildOrder(Child: TComponent; Order: Integer); override;
 procedure SetGroupIndex(AValue: Byte);
 procedure SetImageIndex(AValue: TImageIndex);
 procedure SetParentComponent(AValue: TComponent); override;
 procedure SetShortCut(const AValue: TShortCut);
 procedure SetShortCutKey2(const AValue: TShortCut);
 procedure SetVisible(AValue: Boolean);
 procedure UpdateWSIcon;
 procedure ImageListChange(Sender: TObject);
 property ActionLink: TMenuActionLink;
public
 FCompStyle: LongInt;
 constructor Create(TheOwner: TComponent); override;
 destructor Destroy; override;
 function Find(const ACaption: string): TMenuItem;
 function GetEnumerator: TMenuItemEnumerator;
 GetImageList;
 function GetParentComponent: TComponent; override;
 function GetParentMenu: TMenu; virtual;
 function GetMergedParentMenu: TMenu; virtual;
 function GetIsRightToLeft: Boolean; virtual;
 function HandleAllocated: Boolean;
 function HasIcon: Boolean; virtual;
 function HasParent: Boolean; override;
 procedure InitiateAction; virtual;
 procedure IntfDoSelect; virtual;
 function IndexOf(Item: TMenuItem): Integer;
 function IndexOfCaption(const ACaption: string): Integer; virtual;
 procedure InvalidateMergedItems;
 function VisibleIndexOf(Item: TMenuItem): Integer;
 Add;
 procedure AddSeparator;
 procedure Click; virtual;
 procedure Delete(Index: Integer);
 procedure HandleNeeded; virtual;
 procedure Insert(Index: Integer; Item: TMenuItem);
 procedure RecreateHandle; virtual;
 procedure Remove(Item: TMenuItem);
 procedure UpdateImage(forced: Boolean=False);
 procedure UpdateImages(forced: Boolean=False);
 function IsCheckItem: Boolean; virtual;
 function IsLine: Boolean;
 function IsInMenuBar: Boolean; virtual;
 procedure Clear;
 function HasBitmap: Boolean;
 function GetIconSize(ADC: HDC; DPI: Integer=0): TPoint; virtual;
 function RethinkLines: Boolean;
 procedure RemoveAllHandlersOfObject(AnObject: TObject); override;
 procedure AddHandlerOnDestroy(const OnDestroyEvent: TNotifyEvent; 
 AsFirst: Boolean=False);
 procedure RemoveHandlerOnDestroy(const OnDestroyEvent: TNotifyEvent);
 procedure AddHandler(HandlerType: TMenuItemHandlerType; 
 const AMethod: TMethod; AsFirst: Boolean=False);
 procedure RemoveHandler(HandlerType: TMenuItemHandlerType; 
 const AMethod: TMethod);
 property Merged: TMenuItem;
 property MergedWith: TMenuItem;
 property Count: Integer;
 property Handle: HMENU;
 property Items[Index: Integer]: TMenuItem; default;
 property MergedItems: TMergedMenuItems;
 property MenuIndex: Integer;
 property Menu: TMenu;
 property Parent: TMenuItem;
 property MergedParent: TMenuItem;
 property Command: Word;
 function MenuVisibleIndex: Integer;
 procedure WriteDebugReport(const Prefix: string);
published
 property Action: TBasicAction;
 property AutoCheck: Boolean;
 property AutoLineReduction: TMenuItemAutoFlag;
 property Caption: TTranslateString;
 property Checked: Boolean;
 property Default: Boolean;
 property Enabled: Boolean;
 property Bitmap: TBitmap;
 property GroupIndex: Byte;
 property GlyphShowMode: TGlyphShowMode;
 property HelpContext: THelpContext;
 property Hint: TTranslateString;
 property ImageIndex: TImageIndex;
 property RadioItem: Boolean;
 property RightJustify: Boolean;
 property ShortCut: TShortCut;
 property ShortCutKey2: TShortCut;
 property ShowAlwaysCheckable: Boolean;
 property SubMenuImages: TCustomImageList;
 property SubMenuImagesWidth: Integer;
 property Visible: Boolean;
 property OnClick: TNotifyEvent;
 property OnDrawItem: TMenuDrawItemEvent;
 property OnMeasureItem: TMenuMeasureItemEvent;
end
; 
 TheEnabled: Boolean=True): TMenuItem

Arguments

ACaption

Caption text displayed for the sub-menu.

hCtx

Help context for the sub-menu.

AName

Name for the menu item representing the sub-menu.

Items

Array of menu items for the new sub-menu.

TheEnabledTrue if the menu item for the sub-menu is enabled.

Function result

TMenuItem with the sub-menu created in the routine.

Description

NewSubMenu is a TMenuItem function used to create a sub-menu using the values specified in the arguments to the routine. The return value contains the TMenuItem instance created to represent the sub-menu. It uses the value in aCaption as the caption text for the menu item, and AName contains the name for the sub-menu.

The menu item is created using Nil as the owner of the class instance; it must be added or inserted into the Items for the desired menu instance. Each of the menu Items is added to the class instance, and the remaining arguments are assigned to the corresponding properties for the sub-menu (menu item).

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.