I am trying to Disable() / Enable() menuitems as they become valid depending upon what else has happened in a program.
The problem is that
MENUITEM <oItem> PROMPT <cPrompt> ACTION <uAction> is setting <oItem> to nil rather than the new menu item. I have modified tutor04.prg to demonstrate the problem:
- Code: Select all Expand view RUN
#include "FiveLinux.ch"
static oWnd
function Main()
local lVal := .t., cName := "Hello", cItem, cLbx, nVal := 100, oBar
DEFINE WINDOW oWnd TITLE "Testing controls" ;
MENU BuildMenu()
DEFINE BUTTONBAR oBar OF oWnd
DEFINE BUTTON OF oBar RESOURCE "gtk-new" ACTION MsgInfo( "New" )
DEFINE BUTTON OF oBar RESOURCE "gtk-open" ACTION MsgInfo( "Open" )
DEFINE BUTTON OF oBar RESOURCE "gtk-save" ;
ACTION MsgInfo( "Save" ) GROUP
DEFINE BUTTON OF oBar RESOURCE "gtk-quit" ACTION oWnd:End()
@ 9, 1 SAY "A Say" OF oWnd
@ 12, 2 CHECKBOX lVal PROMPT "Click me" OF oWnd
@ 15, 2 GET cName OF oWnd
@ 18, 2 COMBOBOX cItem OF oWnd ITEMS { "one", "two", "three" }
@ 9, 22 LISTBOX cLbx OF oWnd ITEMS { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" }
@ 21, 2 METER nVal TOTAL 200 OF oWnd
@ 24, 2 IMAGE FILENAME "flh.gif" OF oWnd
@ 26, 30 BUTTON "" OF oWnd ACTION MsgInfo( cLbx ) RESOURCE "gtk-ok"
@ 26, 39 BUTTON "" OF oWnd ACTION MsgInfo( cItem ) RESOURCE "gtk-cancel"
SET MSGBAR OF oWnd TO " FiveLinux - (c) FiveTech Software 2008"
ACTIVATE WINDOW oWnd ;
VALID MsgYesNo( "Are you sure ?" ) ;
ON RIGHT CLICK MsgInfo( "right click" )
return nil
function BuildMenu()
local oMenu
local m2 // I added this variable
MENU oMenu
MENUITEM "One"
MENU
MENUITEM "First" RESOURCE "gtk-new" ACTION MsgInfo( "New" )
MENU
MENUITEM "One"
MENUITEM m2 PROMPT "Two" // and modified this line so that m2 should be this menu item
SEPARATOR
MENUITEM "Three"
ENDMENU
MENUITEM "Second" RESOURCE "gtk-quit" ACTION oWnd:End()
ENDMENU
MENUITEM "Two" ACTION MsgInfo( "Two" )
MENUITEM "Three" ACTION MsgInfo( "Three" )
ENDMENU
MsgInfo( ValType( m2 ) ) // I added this MsgInfo which tells us that m2 is Undefined. Why?
m2:Disable() // so this line produces an error.
return oMenu
When I look at FiveLinux.ch I see that the MENUITEM command is being preprocessed into a call to MenuAddItem()
- Code: Select all Expand view RUN
#xcommand MENUITEM [ <oMenuItem> PROMPT ] [<cPrompt>] ;
[ ACTION <uAction> ] ;
[ <resource: RESOURCE, NAME, RESNAME> <cResName> ] ;
=> ;
[ <oMenuItem> := ] MenuAddItem( <cPrompt>,;
[ \{|o| <uAction> \} ], <cResName> )
I can't find MenuAddItem() but my guess is it must be returning nil. As I can't find it I can't attempt to fix it.
But, as always, my diagnosis could be wrong.
Regards
Doug