FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour recursive value problem
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
recursive value problem
Posted: Fri May 09, 2025 10:51 AM
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?
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
 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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: recursive value problem
Posted: Fri May 09, 2025 11:37 AM
Dear Silvio,

Typicall case to use a detached local:
  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
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: recursive value problem
Posted: Fri May 09, 2025 12:19 PM
Antonio Linares wrote: Dear Silvio,

Typicall case to use a detached local:
  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

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




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

Continue the discussion