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.
Saber que buttons se selecciono
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Saber que buttons se selecciono
@ 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 }
ACTION ( nSelccion:= eval( makeBlock(nI) ), lExit := .T.,oDlg:End() )
...
function makeBlock( i )
return {| u | i }
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Saber que buttons se selecciono
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
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
Re: Saber que buttons se selecciono
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.
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.
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Saber que buttons se selecciono
Prueba esto - probado y funciona.
Saludos,
James
Saludos,
James
Code: Select all
#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