Popup Menu
TTMSFNCPopupMenu is a cross-platform context menu component for Windows and macOS. It supports hierarchical item structures, multiple item types (standard, separator, check, toolbar), embedded controls, and extensive appearance customization.
Key class: TTMSFNCPopupMenu
Note
TTMSFNCMenuItem defines the item's logical configuration (text, icons, sub-items, events). TTMSFNCMenuItemControl is the runtime control rendered when the menu is shown. In most events you work with TTMSFNCMenuItemControl; access the original configuration via its MenuItem property.
Basic Usage
uses
FMX.TMSFNCPopupMenu;
procedure TForm1.CreateMenu;
var
MenuItem: TTMSFNCMenuItem;
begin
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Copy');
MenuItem.OnClick := CopyClick;
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Paste');
MenuItem.OnClick := PasteClick;
TMSFNCPopupMenu1.AddMenuSeparatorItem;
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Options');
MenuItem.AddMenuItem('Option 1');
MenuItem.AddMenuItem('Option 2');
// Assign to a control for right-click
MyControl.PopupMenu := TMSFNCPopupMenu1;
end;
// Or display programmatically
TMSFNCPopupMenu1.Popup(X, Y);
Checkable Items and Groups
Use mitCheck items with a shared GroupName for radio-style selection:
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Small', mitCheck);
MenuItem.GroupName := 'Size';
MenuItem.Checked := True;
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Medium', mitCheck);
MenuItem.GroupName := 'Size';
MenuItem := TMSFNCPopupMenu1.AddMenuItem('Large', mitCheck);
MenuItem.GroupName := 'Size';
// Retrieve the checked item:
MenuItem := TMSFNCPopupMenu1.GetCheckedMenuItemByGroupName('Size');
Embedded Controls
Embed any control inside a menu item:
var
MenuItem: TTMSFNCMenuItem;
SearchEdit: TEdit;
begin
MenuItem := TMSFNCPopupMenu1.AddMenuItem('', mitDefault);
MenuItem.Selectable := False;
SearchEdit := TEdit.Create(Self);
SearchEdit.Width := 150;
SearchEdit.TextPrompt := 'Search...';
MenuItem.Control := SearchEdit;
MenuItem.ControlAlignment := caClient;
end;
Toolbar Items
Use mitToolBar items to create compact button groups:
var
ToolbarItem, ButtonItem: TTMSFNCMenuItem;
begin
ToolbarItem := TMSFNCPopupMenu1.AddMenuItem('', mitToolBar);
ButtonItem := ToolbarItem.AddMenuItem('Bold', mitDefault);
ButtonItem.BitmapName := 'Bold';
ButtonItem.Hint := 'Bold (Ctrl+B)';
ButtonItem.ShowHint := True;
end;
Dynamic Menus
Use OnGetNumberOfPopupMenuItems and OnMenuItemControlAdded to build menus dynamically from data:
procedure TForm1.DoGetNumberOfPopupMenuItems(Sender: TObject;
var ADisplayItemCount: Integer);
begin
ADisplayItemCount := MyDataList.Count + 2;
end;
procedure TForm1.DoMenuItemControlAdded(Sender: TObject;
AMenuItemControl: TTMSFNCMenuItemControl);
begin
case AMenuItemControl.Index of
0: begin
AMenuItemControl.Text := 'Recent Files';
AMenuItemControl.Selectable := False;
end;
1: AMenuItemControl.ItemType := mitSeparator;
else
AMenuItemControl.Text := MyDataList.ToArray[AMenuItemControl.Index - 2].Key;
end;
end;
Custom Appearance
var
mp: TTMSFNCPopupMenuAppearance;
dip: TTMSFNCMenuItemAppearance;
begin
mp := TMSFNCPopupMenu1.Appearance;
mp.Fill.Color := $FF1E1E1E;
mp.Stroke.Color := $FF3A3A3A;
mp.MenuRounding := 12;
dip := mp.DefaultItemAppearance;
dip.Fill.Color := gcNull;
dip.Font.Color := $FFE4E4E4;
dip.SelectedFill.Color := $FF0E639C;
dip.SelectedFontColor := gcWhite;
dip.ItemRounding := 6;
dip.ItemHeight := 32;
end;
Properties Reference
TTMSFNCPopupMenu
| Property | Description |
|---|---|
Appearance |
Visual appearance settings for the menu |
BitmapContainer |
Centralized bitmap management |
Items |
Collection of TTMSFNCMenuItem |
TTMSFNCPopupMenuAppearance
| Property | Description |
|---|---|
Fill / Stroke |
Background fill and border stroke |
MenuRounding |
Corner radius (default: 8) |
MenuMargins |
Internal margins |
DefaultItemAppearance |
Default item appearance settings |
MinimumAutoSizeItemHeight |
Minimum item height (default: 23) |
CheckedIcon / SubMenuIcon |
Icons for checked and sub-menu items |
PopupMenuPlacement |
Placement strategy (default: ppAbsolute) |
TTMSFNCMenuItem
| Property | Description |
|---|---|
Text / Note |
Main text and secondary right-aligned text |
ItemType |
mitDefault, mitSeparator, mitCheck, mitToolBar, mitDropDownButton |
Enabled / Checked / Selectable |
State flags |
GroupName |
Radio-style group |
Bitmap / BitmapName |
Item icon |
Items |
Sub-items collection |
ShortCut |
Keyboard shortcut |
Control / ControlAlignment / ControlPosition |
Embedded control |
Action |
Associated action |
OnClick |
Click event |
TTMSFNCMenuItemAppearance
| Property | Description |
|---|---|
Fill / SelectedFill / DisabledFill |
Background fills by state |
Font / SelectedFontColor / DisabledFontColor |
Font settings by state |
ItemRounding |
Corner radius (default: 2) |
ItemHeight |
Fixed height (-1 for auto) |
LeftTextIndent |
Left text indentation (default: 24) |
Events
| Event | Description |
|---|---|
OnPopup / OnClose |
Before show / after close |
OnMenuItemClick |
Default handler for items without individual OnClick |
OnMenuItemAdd |
Filter items on addition |
OnMenuItemControlAdded |
After a control is added; use for dynamic population |
OnMenuItemSelectable |
Customize item selectability |
OnItemCheck |
Item checked/unchecked |
OnGetNumberOfPopupMenuItems / OnGetNumberOfSubMenuItems |
Dynamic item count |
OnBeforeDrawMenuItem / OnAfterDrawMenuItem |
Custom drawing around items |
OnGetContextMenu / OnGetPopupMenuForContextMenu |
Context menu customization (Edge browser integration) |