Menu Help

Menu Help

Postby PeterHarmes » Mon Jun 29, 2009 8: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: Select all  Expand view

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
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Menu Help

Postby nageswaragunupudi » Mon Jun 29, 2009 12:40 pm

here is your problem
Code: Select all  Expand view
           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: Select all  Expand view
           FOR nCount := 1 TO Len(aVehicles)
                MENUITEM aVehicles[nCount] ACTION ::UpdateVehc( oMenuItem:cPrompt )
            NEXT
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Menu Help

Postby PeterHarmes » Mon Jun 29, 2009 12:59 pm

Thanks, this has solved my problem :)

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests