Button and array

Button and array

Postby Silvio » Thu Jul 20, 2006 10:15 am

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
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby James Bott » Fri Jul 21, 2006 11:15 pm

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[i]),3) }

// Column title (date)
static function makeBlock2(i)
return {|u| left(dtoc( aShipDate[i] ),5) }
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Silvio » Sun Jul 23, 2006 10:41 pm

yes ok I understand..but
but in my source How I can make it ?

Regards
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 39 guests