Page 1 of 1

Detached Local

PostPosted: Thu Sep 14, 2023 10:32 pm
by Jimmy
hi,

i have something like this
Code: Select all  Expand view
  MENUITEM "Player"
   MENU
   MENUITEM "Player &1" ACTION PlayNoNext(1)
   MENUITEM "Player &2" ACTION PlayNoNext(2)
   MENUITEM "Player &3" ACTION PlayNoNext(3)
   MENUITEM "Player &4" ACTION PlayNoNext(4)
   MENUITEM "Player &5" ACTION PlayNoNext(5)
   MENUITEM "Player &6" ACTION PlayNoNext(6)
   MENUITEM "Player &7" ACTION PlayNoNext(7)
   MENUITEM "Player &8" ACTION PlayNoNext(8)
   MENUITEM "Player &9" ACTION PlayNoNext(9)
   ENDMENU

now i want to make this while it can be Different Layout
Code: Select all  Expand view
  MENUITEM "Player"
   MENU
      AddMenuPlayer()
   ENDMENU

but i always get only "last" Element ...
Code: Select all  Expand view
#include "fivewin.ch"
#define Use_Detach_Local
STATIC nRow     := 3
STATIC nCol     := 3

function Main()
local oWnd, oMenu

   DEFINE WINDOW oWnd MENU MyMenu2()
   ACTIVATE WINDOW oWnd CENTERED

return nil

function MyMenu2()
LOCAL oPopup

   MENU oPopup
   MENUITEM "Player"
      MENU
#ifdef Use_Detach_Local
      AddMenuPlayer()
#else
      MENUITEM "Player &1" ACTION PlayNoNext(1)
      MENUITEM "Player &2" ACTION PlayNoNext(2)
      MENUITEM "Player &3" ACTION PlayNoNext(3)
      MENUITEM "Player &4" ACTION PlayNoNext(4)
      MENUITEM "Player &5" ACTION PlayNoNext(5)
      MENUITEM "Player &6" ACTION PlayNoNext(6)
      MENUITEM "Player &7" ACTION PlayNoNext(7)
      MENUITEM "Player &8" ACTION PlayNoNext(8)
      MENUITEM "Player &9" ACTION PlayNoNext(9)
#endif
      ENDMENU
   ENDMENU

RETURN oPopup

PROCEDURE PlayNoNext(nNo)
   Msginfo(STR(nNo))
RETURN

PROCEDURE AddMenuPlayer()
LOCAL xx,yy,bBlock, nCount := 0

   FOR yy := 1 TO nRow
      xx := 1
      FOR xx := 1 TO nCol
       nCount++
       MENUITEM "Player "+LTRIM(STR(nCount)) ACTION  DoDeachLocal(nCount)
    NEXT
   NEXT
RETURN

FUNCTION DoDeachLocal(nNo)
LOCAL cRet := "{|| PlayNoNext(" + STR(nNo) +") }"
LOCAL bBlock := &(cRet)

   EVAL(bBlock)

RETURN nil
 

who can help me please

Re: Detached Local

PostPosted: Fri Sep 15, 2023 2:57 am
by nageswaragunupudi
METHOD-1
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd, oMenu, n

   MENU oMenu
      MENUITEM "Player"
      MENU
         for n := 1 to 9
            PlayMenuItem( n )
         next
      ENDMENU
   ENDMENU

   DEFINE WINDOW oWnd MENU oMenu
   ACTIVATE WINDOW oWnd CENTERED

return nil

static function PlayMenuItem( n )

   MENUITEM "Player &" + Str( n, 1, 0 ) ACTION PlayNoNext( n )

return nil

static function PlayNoNext( n );MsgInfo( n );return nil
 


METHOD-2
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd, oMenu, n

   MENU oMenu
      MENUITEM "Player"
      MENU
         for n := 1 to 9
            MENUITEM "Player &" + Str( n, 1, 0 ) ;
               BLOCK PlayItemAction( n )
         next
      ENDMENU
   ENDMENU

   DEFINE WINDOW oWnd MENU oMenu
   ACTIVATE WINDOW oWnd CENTERED

return nil

static function PlayItemAction( n )
return { || PlayNoNext( n ) }

static function PlayNoNext( n );MsgInfo( n );return nil
 


METHOD-3
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd, oMenu, n

   MENU oMenu
      MENUITEM "Player"
      MENU
         for n := 1 to 9
            MENUITEM "Player &" + Str( n, 1, 0 ) ;
               ACTION PlayNoNext( Val( Right( oMenuItem:cPrompt, 1 ) ) )
         next
      ENDMENU
   ENDMENU

   DEFINE WINDOW oWnd MENU oMenu
   ACTIVATE WINDOW oWnd CENTERED

return nil

static function PlayNoNext( n );MsgInfo( n );return nil
 


METHOD-4
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd, oMenu, oItem, n

   MENU oMenu
      MENUITEM "Player"
      MENU
         for n := 1 to 9
            MENUITEM oItem PROMPT "Player &" + Str( n, 1, 0 ) ;
               ACTION PlayNoNext( oMenuItem:Cargo )
            oItem:Cargo := n
         next
      ENDMENU
   ENDMENU

   DEFINE WINDOW oWnd MENU oMenu
   ACTIVATE WINDOW oWnd CENTERED

return nil

static function PlayNoNext( n );MsgInfo( n );return nil
 

Re: Detached Local

PostPosted: Fri Sep 15, 2023 10:58 am
by Jimmy
hi,

AH, this Way it work, THX