FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Saber que buttons se selecciono
Posts: 170
Joined: Sat Aug 07, 2010 11:36 PM
Saber que buttons se selecciono
Posted: Tue Nov 09, 2010 07: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.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Saber que buttons se selecciono
Posted: Wed Nov 10, 2010 01: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 }
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Re: Saber que buttons se selecciono
Posted: Wed Nov 10, 2010 01:54 AM

so what does it mean?

Thank you

Harvey
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Saber que buttons se selecciono
Posted: Wed Nov 10, 2010 01: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 170
Joined: Sat Aug 07, 2010 11:36 PM
Re: Saber que buttons se selecciono
Posted: Thu Nov 11, 2010 02: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.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Saber que buttons se selecciono
Posted: Thu Nov 11, 2010 05:36 PM
Prueba esto - probado y funciona.

Saludos,
James

Code (fw): Select all Collapse
#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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion