Page 1 of 1

Button and array

Posted: Thu Jul 20, 2006 10:15 am
by Silvio
If i want associate a action to many buttons with matricial array How i can I make it ? and to return the number of the button ?

example :

tot1:=20
to2:=8

bAction := {|oBtn| prenotamenu( oBtn ) ,oBtn:cCaption := "",oBtn:Disable( VK_RBUTTON ), oBtn:Refresh() }

aBtn:= { Array( tot1 ), Array( tot2 ) }
totarray := tot1*tot2
aAct := Array( totarray )
AFill( aAct, bAction )



nDisponibili:=0
nOccupati:=0
n := 1
fila := 60
FOR i := 1 TO tot2
nPassLarg := 0
col := 10


FOR k := 1 TO tot1

aCapt:=Str( camere->camera,3,0)
IF ! Empty(Pre_cam->Nome)
cbitmap="SEAT1" //rosso
nOccupati++
ELSE
nDisponibili++
cbitmap="SEAT2" // verde
Endif
IF ! Empty(Pre_cam->Nome)

@ Fila,(Col+nPassLarg) SBUTTON aBtn[n] RESOURCE cbitmap PIXEL;
OF oWnd ;
FONT oFont2 ;
CAPTION aCapt ;
COLOR GetSysColor(13), GetSysColor(1) ;
TEXT ON_CENTER ;
NOBOX ;
MESSAGE "Pulsante sinistro: Inserire la prenotazione. " + ;
"Pulsante destro: Cancellare la prenotazione." ;
TOOLTIP oemtoansi(aCapt ) ;
ACTION aAct



ELSE

@ Fila,(Col+nPassLarg) SBUTTON aBtn[n] RESOURCE cbitmap PIXEL;
OF oWnd ;
FONT oFont2 ;
CAPTION aCapt ;
COLOR GetSysColor(13), GetSysColor(1) ;
TEXT ON_CENTER ;
NOBOX ;
MESSAGE "Pulsante sinistro: Inserire la prenotazione. " + ;
"Pulsante destro: Cancellare la prenotazione." ;
TOOLTIP oemtoansi(aCapt ) ;
ACTION aAct


ENDIF









//ciclo
col += 65
n++
CAMERE->(dbskip())
cPosNome :=""
NEXT
fila +=65
NEXT

nAct := 1
For nEle := 1 To Len( aBtn )
For nSub := 1 To Len( aBtn[ nEle ] )
aBtn[ nEle, nSub ]:Cargo := aCapt[ nAct++ ]
aBtn[ nEle, nSub ]:bRClicked := {| oBtn| fCancel( oBtn ) }
Next
Next

thanks

Posted: Fri Jul 21, 2006 11:15 pm
by James Bott
Silvio,

You may have to use "detached locals" for your counters.

Because the counter has already been completely through the loop before the dialog gets initialized, the counter is at the maximum value so it is as if it only went through the loop once.

A detached local is a local var that is captured in a codeblock. Even though it is a local var, it stays in scope until the codeblock is out of scope.

Here are some example codeblocks to make detached locals. If you have more than one counter, you will need a separate function for each one.

James

---------------------------------------
Detached Locals

Simple example:

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

Here is another example:

Static Function MyDetach( i, a )
Return( {|x| if( x == NIL, a[ i ], a[ i ] := x } ) )

// Column title (day of week)
static function makeBlock1(i)
return {|u| left(cdow(aShipDate),3) }

// Column title (date)
static function makeBlock2(i)
return {|u| left(dtoc( aShipDate ),5) }

Posted: Sun Jul 23, 2006 10:41 pm
by Silvio
yes ok I understand..but
but in my source How I can make it ?

Regards