recursive value problem

Post Reply
User avatar
Silvio.Falconi
Posts: 7256
Joined: Thu Oct 18, 2012 7:17 pm
Has thanked: 2 times
Been thanked: 30 times

recursive value problem

Post by Silvio.Falconi »

I have a problem with a for/next loop. The problem is that in this loop it creates a checkbox control which has on change and calls a function changeBrw(nIndex). The problem is that nIndex is always 5, that is the last value. How can I solve it? I was thinking of a code block but I can't find it. Can you help me please?

Code: Select all | Expand

FOR nIndex := 1 TO Min( nFields, 5 ) // Limita a 5 checkbox come da specifica
      IF Len( ::aFields[nIndex] ) >= 2
         @ nRow, nCol CHECKBOX ::aControls[nIndex] ;
            VAR ::aCheckboxes[nIndex] ;
            PROMPT ::aFields[nIndex][2] ;
            OF ::oDlg ;
            SIZE 90, 20 ;
            PIXEL ;
            COLOR CLR_BLACK, RGB(235, 243, 245) ;
            FONT ::oFontBold ;
            ON CHANGE ( oThis:ChangeSizeBrw( nIndex ) )
         nCol += 100
      ENDIF
      If nIndex==5
         EXIT
      Endif

   NEXT
to avoid it making the mistake of going to take the number 6 when instead of elements in the array there are 5 I inserted these lines at the end of the loop

Code: Select all | Expand

 If nIndex==5
         EXIT
      Endif
but then the nIndex passed on oThis:ChangeSizeBrw( nIndex ) is allways 5

any solution pls ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Antonio Linares
Site Admin
Posts: 42844
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 181 times
Been thanked: 124 times
Contact:

Re: recursive value problem

Post by Antonio Linares »

Dear Silvio,

Typicall case to use a detached local:

Code: Select all | Expand

  FOR nIndex := 1 TO Min( nFields, 5 ) // Limita a 5 checkbox come da specifica
      IF Len( ::aFields[nIndex] ) >= 2
         @ nRow, nCol CHECKBOX ::aControls[nIndex] ;
            VAR ::aCheckboxes[nIndex] ;
            PROMPT ::aFields[nIndex][2] ;
            OF ::oDlg ;
            SIZE 90, 20 ;
            PIXEL ;
            COLOR CLR_BLACK, RGB(235, 243, 245) ;
            FONT ::oFontBold ;
         ::aControls[ nIndex ]:bChanged = GenChangeBlock( ::aControls[ nIndex ], nIndex )   
         nCol += 100
      ENDIF
      If nIndex==5
         EXIT
      Endif
   NEXT
   
   function GenChangeBlock( oCbx, nIndex )
   
   return { || oCbx:ChageSizeBrw( nIndex ) }
   
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 7256
Joined: Thu Oct 18, 2012 7:17 pm
Has thanked: 2 times
Been thanked: 30 times

Re: recursive value problem

Post by Silvio.Falconi »

Antonio Linares wrote: Fri May 09, 2025 11:37 am Dear Silvio,

Typicall case to use a detached local:

Code: Select all | Expand

  FOR nIndex := 1 TO Min( nFields, 5 ) // Limita a 5 checkbox come da specifica
      IF Len( ::aFields[nIndex] ) >= 2
         @ nRow, nCol CHECKBOX ::aControls[nIndex] ;
            VAR ::aCheckboxes[nIndex] ;
            PROMPT ::aFields[nIndex][2] ;
            OF ::oDlg ;
            SIZE 90, 20 ;
            PIXEL ;
            COLOR CLR_BLACK, RGB(235, 243, 245) ;
            FONT ::oFontBold ;
         ::aControls[ nIndex ]:bChanged = GenChangeBlock( ::aControls[ nIndex ], nIndex )   
         nCol += 100
      ENDIF
      If nIndex==5
         EXIT
      Endif
   NEXT
   
   function GenChangeBlock( oCbx, nIndex )
   
   return { || oCbx:ChageSizeBrw( nIndex ) }
   
::aControls[ nIndex ]:bChange := GenChangeBlock( ::aControls[ nIndex ], nIndex ) make me error

Code: Select all | Expand

Error occurred at: 05/09/25, 14:19:59
   Error description: Error BASE/1004  Message not found: TCHECKBOX:CHAGESIZEBRW
   Args:
     [   1] = O   TCHECKBOX

Stack Calls
===========
   Called from: ../../../tobject.prg => __ERRRT_SBASE( 0 )
   Called from: ../../../tobject.prg => TCHECKBOX:ERROR( 0 )
   Called from: ../../../tobject.prg => (b)HBOBJECT( 0 )
   Called from: ../../../tobject.prg => TCHECKBOX:MSGNOTFOUND( 0 )
   Called from: ../../../tobject.prg => TCHECKBOX:CHAGESIZEBRW( 0 )
   Called from: Tfiltro.prg => (b)GENCHANGEBLOCK( 104 )
   Called from: .\source\classes\checkbox.prg => TCHECKBOX:CLICK( 153 )
   Called from: .\source\classes\control.prg => TCHECKBOX:HANDLEEVENT( 18
I made

::aControls[nIndex]:bchange := ::EvalBlock(nIndex)

METHOD EvalBlock(n) CLASS TFiltro
local nCopy := n
return { || ::ChangeSizeBrw(nCopy ) }


and seem run ok only I have other problems now


on ::ChangeSizeBrw(nIndex ) nIndex is 1 but the if I make xbrowser ::aCheckboxes it show all false and only last true

Image


but it is bad beacuse I click on first checkbox and I must have the first .t. and not .f.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Post Reply