Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Menu.PopUp

Pops up the menu at the specified location.

Component Version macOS Windows Linux Server iOS SDK
Menu 4.1 ✅ Yes ✅ Yes ❌ No ❌ No ❌ No
MBS( "Menu.PopUp"; menu; mode { ; x; y; window; item; objectName } )   More

Parameters

Parameter Description Example Flags
menu The reference to the menu. Please create one with Menu.CreateMenu. $menu
mode The mode to use.
Can be "mouse", "screen", "object" or "window".
Default is mouse for leaving away the parameter or passing empty text.
Version 8.3 adds mode "content" to make it relative to the content part of the window, below toolbars.
"mouse"
x The relative x coordinates for the position relative to the mouse, screen or window. 0 Optional
y The relative y coordinates for the position relative to the mouse, screen or window. 0 Optional
window The window reference for the showing menu relative to a window. $window Optional
item The menu item to be positioned at the specified location in the view.
macOS only.
$item Optional
objectName The object name for mode=object. "web" Optional

Result

Returns 1, 0 or error.

Description

Pops up the menu at the specified location.
The top left corner of the specified item (if specified, item must be present in the receiver) is positioned at the specified location in the specified view, interpreted in the view's own coordinate system.
If you call this on the server for Web Direct, the menu will show on the server, not in the browser.
Returns 1 if item was selected or 0 if not.
If you like to show a context menu only when user did a right mouse click, you can use the EventMonitor.LastMouseClickButton function to check mouse state.

Examples

Show a context menu based on a table with menu entries:

# go to layout with menu entries
Go to Layout [ “REP” (REP Reports) ]
# this script can be called with various groups
Set Variable [ $type ; Value: Get(ScriptParameter) ]
# make a new menu
Set Variable [ $menu ; Value: MBS( "Menu.CreateMenu") ]
# loop over records
Go to Record/Request/Page [ First ]
Loop
    # if group matches
    If [ REP Reports::Group = $type ]
        # add new menu item with title from table
        Set Variable [ $item ; Value: MBS( "MenuItem.CreateMenuItem"; REP Reports::LabelReport) ]
        # define which script to call if menu item is selected
        Set Variable [ $r ; Value: MBS( "MenuItem.SetScriptAction"; $item; Get(FileName); REP Reports::Script ) ]
        # add item to menu
        Set Variable [ $r ; Value: MBS( "Menu.AddItem"; $menu; $item ) ]
    End If
    # next record?
    Go to Record/Request/Page [ Next ; Exit after last ]
End Loop
# switch layout back
Go to Layout [ original layout ]
# Show menu
Set Variable [ $r ; Value: MBS( "Menu.PopUp"; $menu; "mouse") ]
# Cleanup memory
Set Variable [ $r ; Value: MBS( "Menu.Release"; $menu) ]

Show menu and show selection:

Set Variable [$menu; Value:MBS("Menu.CreateMenu")]
# create menu items...
Set Variable [$item; Value:MBS("MenuItem.CreateMenuItem"; "Hello World")]
Set Variable [$r; Value:MBS("MenuItem.SetTag"; $item; "secret value")]
Set Variable [$r; Value:MBS("Menu.AddItem"; $menu; $item)]
#
#show menu
Set Variable [$m; Value:MBS("Menu.PopUp"; $Menu; "mouse")]
#
#you selected something?
If [$m = 1]
    Set Variable [$selectedItem; Value:MBS("Menu.SelectedItem"; $menu)]
    Set Variable [$selectedTitle; Value:MBS("MenuItem.GetTitle"; $selectedItem)]
    Set Variable [$selectedTag; Value:MBS("MenuItem.GetTag"; $selectedItem)]
    #
    Show Custom Dialog ["Auswahl"; $selectedItem & ¶ & $selectedTitle & ¶ & $selectedTag]
End If
Set Variable [$m; Value:MBS("Menu.Release"; $Menu; 1)]

Choose from menu with one Let statement:

// show menu with one let statement
Let ( [
// some list of menu entries
valuelist = "xxx¶yyy¶zzz" ;
// create menu from definition
menu = MBS ( "Menu.DefineQuickMenu"; "x" ; valuelist ) ;
// show menu near mouse
result = MBS ( "Menu.popup" ; menu ; "mouse" ) ;
// query selected item number
item = IF ( result = 1 ; MBS("Menu.SelectedItem"; menu) ) ;
// query title for that item
title = IF ( Length ( item > 0 ) ; MBS ( "MenuItem.GetTitle" ; item ) ) ;
// release memory
r = MBS ( "Menu.Release"; menu ) ] ;
// return the selected title
title )

Run menu at logo object:

MBS("Menu.PopUp"; $Menu; "object"; 0; 0; Get(WindowName); ""; "logo")

See also

Release notes

  • Version 8.3

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 15th April 2023


Menu.NumberOfItems - Menu.Release