FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Menu Help
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Menu Help
Posted: Mon Jun 29, 2009 08:25 AM
Hi,

I'm trying to create a popup menu from my xBrowse that builds a list based on an open database, i then want to pass a field from that database to the action.

First i build an array of records from the database, and then i add menuitems to the menu. The list of items appear correctly, however, when i click on the item i get a bound error. Can anyone tell me where i'm going wrong?

Code (fw): Select all Collapse
METHOD SchedPopup() CLASS Schedule
    Local oMenu
    LOCAL nCount    := 0
    LOCAL aVehicles := {}
    PRIVATE cSced   := ::cScedAlias
    PRIVATE cVehc   := ::cVehcAlias
    PRIVATE cFunc   := "::UpdateVehc("
    IF !::lVehicle
        &cVehc.->(DBGOTOP())
        DO WHILE !&cVehc.->(EOF()) 
            Aadd(aVehicles, &cVehc.->VEHCL_NBR)
            &cVehc.->(DBSKIP())
        ENDDO   
    ENDIF
    MENU oMenu POPUP                             // Creating a POPUP
        MENUITEM "Edit Ticket"                 ACTION ::AmendTicket()
        MENUITEM "View Ticket"                 ACTION ::ViewTicket()
        MENUITEM "Confirm Ticket"              ACTION ::Confirm()
        MENUITEM "Print Ticket"                ACTION ::PrintTicket()
        MENUITEM "Allocate Ticket"             ACTION ::Allocate()
        MENUITEM "Allocate To..."              ACTION .T. 
        MENU
            FOR nCount := 1 TO Len(aVehicles)
                MENUITEM aVehicles[nCount] ACTION ::UpdateVehc(aVehicles[nCount])
            NEXT
        ENDMENU
        MENUITEM "DeAllocate Ticket"           ACTION ::Dealloc() 
        MENUITEM "Edit/View Transaction Notes" ACTION ::TicketNotes()    
        MENUITEM "Edit/View Container Info"    ACTION ::ContainerInfo()
        MENUITEM "Edit/View Additional Items"  ACTION ::OrdItems()
        IF !Empty(&cSced.->OR_VEHICLE)
            SEPARATOR 
            MENUITEM "Open Schedule For Highlighted Vehicle" ACTION ::VehicleSchedule()
            MENUITEM "Open Vehicle Diary"                    ACTION ::VehicleDiary() 
        ENDIF
        SEPARATOR
        MENUITEM "Move To New Site"            ACTION ::MoveSite()
        MENUITEM "Move To New Date"            ACTION ::MoveDate()
        MENUITEM "Move To New Schedule"        ACTION ::ChangeScedType()
        SEPARATOR
        MENUITEM "Send SMS To Customer"        ACTION SMSMessage(GetCustMobileNo(::cScedAlias), "") 
        MENUITEM "Send SMS To Site Address"    ACTION SMSMessage( "", GetSiteMobileNo(::cOrdAlias))  
    ENDMENU
return oMenu


Thanks in advance,

Pete
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Menu Help
Posted: Mon Jun 29, 2009 12:40 PM
here is your problem
Code (fw): Select all Collapse
            FOR nCount := 1 TO Len(aVehicles)
                MENUITEM aVehicles[nCount] ACTION ::UpdateVehc(aVehicles[nCount])
            NEXT

By the time a menu item is clicked, nCount's value is Len(aVehicles) + 1.
This is commonly known pitfall in assigning action blocks in a loop. You need to use a separate function to generate the codeblock using the concept of detached locals.

But in your present case, I suggest a different kind of solution. Please try this:
Code (fw): Select all Collapse
            FOR nCount := 1 TO Len(aVehicles)
                MENUITEM aVehicles[nCount] ACTION ::UpdateVehc( oMenuItem:cPrompt )
            NEXT
Regards



G. N. Rao.

Hyderabad, India
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Re: Menu Help
Posted: Mon Jun 29, 2009 12:59 PM

Thanks, this has solved my problem :)

Pete

Continue the discussion