This final section shows you how to create a dynamic menu for a window. Dynamic menus share the same characteristics of static menus. As with other dynamic objects, you use CREATE statements rather than DEFINE statements to create a menu, submenu, or menu item. You parent these objects together in a hierarchy by setting their PARENT attribute. If you need to delete a dynamic menu before its widget pool is deleted, you use the DELETE OBJECT statement to delete the top-level menu object. The AVM automatically deletes all its child submenus and menu items.

When you define a static menu, you need to define its elements in reverse order, so that you define the submenus before you reference them in the static DEFINE MENU statement. With dynamic menus you do the opposite. You first define the top-level menu, then its submenus, and then each submenu’s menu items. As you create each one, you parent it to the next level up to establish the menu hierarchy.

Create a menu

To create a menu, use this statement:

CREATE MENU menu-handle [ ASSIGN attribute = value [ . . .] ] .

As with other dynamic objects, you can assign one or more attributes as part of the CREATE statement or in separate statements that use the menu handle. Typical menu attributes include:

  • POPUP-ONLY — Set this to true to create a pop-up menu. The default value is false, which means that the AVM creates the menu as a menu bar.
  • TITLE — This is settable only for pop-up menus.
  • SENSITIVE — Set this to false to disable the menu.

To associate a menu with a window, set the MENUBAR attribute of the window handle to the menu handle.

Create a submenu

To create a submenu, use the CREATE SUB-MENU statement:

CREATE SUB-MENU submenu-handle [ ASSIGN attribute = value [ . . .]]
  [ trigger-block ].

Typical attributes you can assign for a submenu include:

  • LABEL — Every submenu must have a unique label.
  • PARENT — Assign the PARENT attribute to the handle of the menu or parent submenu in a hierarchy.
  • SENSITIVE — Set this to false to disable the submenu.

You can also define a trigger block (typically for a CHOOSE trigger) as part of the CREATE statement.

Creating menu items

In a dynamic menu, menu items are individually created objects with their own handles. Because you can delete an entire menu by deleting the top-level menu, or by deleting the procedure that controls the widget pool for the menu, you can normally use the same object handle for all your menu items. Each one must be parented to the submenu that contains it. Therefore, each menu item can be used in only one menu or submenu. Typical menu item attributes include:

  • LABEL — This is the text label for the menu item.
  • PARENT — This is the parent submenu handle.
  • SENSITIVE — Set this to false to disable the menu item.
  • SUBTYPE — The default SUBTYPE is NORMAL, for standard selectable menu items. Other valid values are READ-ONLY (for a read-only menu item), SKIP (for a blank line in the menu), or RULE (to create a line between menu items).