Tech Tip: Getting submenu references
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: February 27, 2015
Below is the method Get_Sub_Menus that takes in a reference to a Parent menu, and return titles and references to all submenus within the parent menu. The method uses the command GET MENU ITEMS to find the submenus.
Note: Submenus must have menu items within them, else GET MENU ITEMS will not return the reference to the submenu.
// Method: GET_SUB_MENUS // $1 - Pointer to parent menu references // $2 - Pointer to array to contain submenu titles // $3 - Pointer to array to comtain submenu references // ---------------------------------------------------- C_POINTER($1;$ParentMenu) C_POINTER($2;$3;$submenuRefs;$submenuTitles) C_LONGINT($i) $ParentMenu:=$1 $submenuTitles:=$2 $submenuRefs:=$3 ARRAY TEXT($aTitles;0) ARRAY TEXT($aRefs;0) GET MENU ITEMS($ParentMenu->;$aTitles;$aRefs) For ($i;1;Size of array($aRefs)) If ($aRefs{$i}#"") APPEND TO ARRAY($submenuTitles->;$aTitles{$i}) APPEND TO ARRAY($submenuRefs->;$aRefs{$i}) Get_Sub_Menus (->$aRefs{$i};$submenuTitles;$submenuRefs) End if End for |
Below is an example of using the method to obtain the references of all the submenus of a parent menu:
$Parent:=Create menu $Child1:=Create menu $Child2:=Create menu APPEND MENU ITEM($Parent;"Parent1") APPEND MENU ITEM($Parent;"Parent2") APPEND MENU ITEM($Parent;"Parent3";$Child1) APPEND MENU ITEM($Child1;"child1") APPEND MENU ITEM($Child1;"child2") APPEND MENU ITEM($Child1;"child3";$Child2) APPEND MENU ITEM($Child2;"child4") ARRAY TEXT($subMenuTitles;0) ARRAY TEXT($submenuRefs;0) Get_Sub_Menus (->$Parent;->$subMenuTitles;->$submenuRefs) RELEASE MENU($Parent) RELEASE MENU($Child1) RELEASE MENU($Child2) |