Sign in Join
FPDoc Onlineexperiment

NewPopupMenu function

In unit Menus

Creates and configures a new pop-up menu with the specified menu items.

Declaration

pascal
function NewPopupMenu(Owner: TComponent; const AName: string; 
 Alignment: TPopupAlignment; AutoPopup: Boolean; 
 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
)
: TPopupMenu

Arguments

Owner

Component which owns the new pop-up menu instance.

AName

Name for the new pop-up menu instance.

Alignment

Alignment relative to the mouse pointer for the pop-up menu instance.

AutoPopupTrue if the pop-up menu is automatically displayed when the mouse is hovered over the component.
Items

Array with the menu items for the new pop-up menu instance.

Function result

TPopUpMenu instance created in the routine.

Description

NewPopupMenu is a TPopUpMenu function used to create and configure a new pop-menu with the values specified in the arguments to the routine. The return value is created using the component in Owner as the owner of the class instance. The value in AName is used in the Name property for the new menu instance. AutoPopUp and Alignment are assigned to the corresponding properties in the new pop-up menu instance.

NewPopupMenu calls an implementation routine to add the menu Items to the new menu instance. It ensures that the Owner for the menu items are updated to reflect the Owner for the new menu instance, and that they are inserted into the Owner component.

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