Saber que buttons se selecciono

Saber que buttons se selecciono

Postby jgayoso » Tue Nov 09, 2010 7:44 pm

Consulta:

Tengo una funsión con un dialogo con x buttons, todos retornan al modulo que llano esta función. Pero la ideas es que retorne un numero que indique que button se selecciono, los botones estan en un arreglo.

Function .....
.
.
DEFINE DIALOG oDlg FROM 15, 30 TO 17+len(tG)+4, 82 FONT oFnt_Texto
for nI:=1 to len(tG)
@nI-1,2 say tG[nI] Font oFnt_Texto
next nI
for nI:=1 to len(aButtons)
@ len(tG), nC BUTTON aButtons[nI] OF oDlg SIZE nLB*5,14 Font oFnt_Button ;
ACTION ( lExit := .T., oDlg:End() )
nC+=nLB
next nIB
ACTIVATE DIALOG oDlg VALID lExit
Return nSeleccion

No he dado con la solución, ¿ Alguna idea ? ¿ Como puedo retornar en la variable "nSeleccion" un valor distinto para cada button ?

Sin son 3 buttons y presiono el primer button retorne 1, 2 el segundo y 3 el tercero.

Se agradece cualquier ayuda.
jgayoso
 
Posts: 170
Joined: Sat Aug 07, 2010 11:36 pm
Location: Chile

Re: Saber que buttons se selecciono

Postby James Bott » Wed Nov 10, 2010 1:22 am

@ len(tG), nC BUTTON aButtons[nI] OF oDlg SIZE nLB*5,14 Font oFnt_Button ;
ACTION ( nSelccion:= eval( makeBlock(nI) ), lExit := .T.,oDlg:End() )

...

function makeBlock( i )
return {| u | i }
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Saber que buttons se selecciono

Postby hag » Wed Nov 10, 2010 1:54 am

so what does it mean?
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: Saber que buttons se selecciono

Postby James Bott » Wed Nov 10, 2010 1:38 pm

Harvey,

He wants to return a number depending on which button was pressed. The compilcation is that you cannot use i directly since it will always be the last value of the loop (in this case 3) becuase the loop has already completed when the dialog is displayed. So the trick is to put i in a codeblock and thus the value of i at the time it was put in the codeblock remains in the codeblock. This technique is called a "detached local."

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Saber que buttons se selecciono

Postby jgayoso » Thu Nov 11, 2010 2:22 pm

James, probe lo indicado pero sin son 2 buttons me responde siempre 3, independiente del buttons presionado.

Local nSeleccion:=1
.
.
.
DEFINE DIALOG oDlg FROM 15, 30 TO 17+len(tG)+4, 82 FONT oFnt_Texto
for nI:=1 to len(tG)
@ len(tG), nC BUTTON aButtons[nI] OF oDlg SIZE nLB*5,14 Font oFnt_Button ;
ACTION ( nSeleccion:=eval( makeBlock(nI) ), lExit := .T., oDlg:End() )
nC+=nLB
next nI

ACTIVATE DIALOG oDlg VALID lExit

Return nSeleccion

function makeBlock( i )
return {| u | i }

Quedo a la espera de alguna respuesta.
jgayoso
 
Posts: 170
Joined: Sat Aug 07, 2010 11:36 pm
Location: Chile

Re: Saber que buttons se selecciono

Postby James Bott » Thu Nov 11, 2010 5:36 pm

Prueba esto - probado y funciona.

Saludos,
James

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

function main()
   msgInfo( Test() )
return nil


Function Test()
   Local nSeleccion:=1, nI:=0, tG:="123", lExit:=.f.
   Local aButtons:={}, aPrompts:={"1","2","3"},nLB:=2
   Local oFnt_Button, oDlg, nC:=4, aSeleccion:={1,2,3}, oBtn

   define font oFnt_Button name "arial"

   DEFINE DIALOG oDlg FROM 15, 30 TO 17+len(tG)+4, 82 //FONT oFnt_Texto

      for nI:=1 to len(tG)

         @ len(tG), nC BUTTON oBtn prompt aPrompts[nI] OF oDlg SIZE nLB*5,14 Font oFnt_Button
         nC+=nLB

         aadd(aButtons,oBtn)
         aButtons[nI]:Cargo:= nI
         aButtons[nI]:bAction:= {|self| nSeleccion:= ::cargo, lExit := .t., oDlg:end() }

      next nI

   ACTIVATE DIALOG oDlg VALID lExit

Return  nSeleccion
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 37 guests