Popup menu bug?

J. Landman Gay jacque at hyperactivesw.com
Mon Jun 1 17:52:47 EDT 2009


Josep wrote:
> Hi list,
> 
> I found this... maybe I doing something wrong but...
> 
> Create a popup menu with many options.
> In the popupmenu put this:
> 
> on menuPick pItemName
>    Global pOldItem
>    
>    put pItemName into fld lbl_search
>    replace "!c" with "" in line lineOffset(pOldItem,button opt_search) of
> button opt_search
>    
>    put "!c" before line lineOffset(pItemName,button opt_search) of button
> opt_search
>    put pItemName into pOldItem
>    
>    switch pItemName
>     
>    end switch
> end menuPick
> 
> For check and uncheck the option selected by the user.
> 
> Put in a button mouseup this:
> 
>   switch the selectedtext of button opt_search
>       case "!cNIF"
>          put "select * from clientes where CLI_NIF like " & quote & "%" &
> fld f_buscar & "%" & quote into tQuery
>          break
>       case "!cTeléfono"
>          put "select * from clientes where CLI_Telefono like " & quote & "%"
> & fld f_buscar & "%" & quote into tQuery
>          break
>       case "!cNombre"
>          put "select * from clientes where CLI_Nombre like " & quote & "%" &
> fld f_buscar & "%" & quote into tQuery
>          break
>       case "!cPoblación"
>          put "select * from clientes where CLI_Poblacion like " & quote &
> "%" & fld f_buscar & "%" & quote into tQuery
>          break
>       default
>          
>    end switch
> 
> The "the selectedtext of button opt_search" ever have the first option.
> But if you don't perform any operation into menuPick the "the selectedtext
> of button opt_search" have the correct option.
> 
> Why?

The checkmark is interfering with the rest of the script. If you remove 
the checkmark instruction it works. You can work around the problem by 
setting the checkmark at the end of the handler, after you have 
processed the rest of the commands. Also, you don't need the global to 
store the last selection, instead just remove all checkmarks from the 
button at once. Also remember to always put all literal names into quotes.

This should work:

on menuPick pItemName
   put pItemName into fld "lbl_search"
   put the menuhistory of btn "opt_search" into tLine -- user choice
   replace "!c" with "" in button "opt_search" -- remove all checkmarks

   switch pItemName -- process the choice, using the item that was chosen
   case "NIF"
     -- do your DB stuff here
     break
   case "Teléfono"
     -- DB stuff
     break
   case "Nombre"
     -- DB stuff
     break
   case "Población"
     -- DB stuff
     break
   default
   end switch
   put "!c" before line tLine of btn "opt_search" -- add checkmark last
end menuPick

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list