Nages test sample ( search in array)

Nages test sample ( search in array)

Postby Silvio.Falconi » Thu Apr 16, 2020 4:30 pm

I'm trying an example that I found on this forum created by NagesWarao
In the example, Nages uses customer.dbf and creates the aData array

I already have the aData array in the source
of course for space reasons I cannot publish the content of my aData but here is an example

aData := {"voce1","voce2","voce3","voce4","voce5","voce6"}



Image


the error if on this line oBrw:bFilterExp := &( cFilter )



I have this error

Code: Select all  Expand view  RUN
Error occurred at: 04/16/20, 18:06:55
   Error description: Error BASE/1068  Argument error: array access
   Args:
     [   1] = C   arco
     [   2] = N   1

Stack Calls
===========
   Called from: search2.prg => (b)XSETFILTER( 72 )
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:ARRAYINCRFILTER( 11157 )


 






the test
Code: Select all  Expand view  RUN


#include 'fivewin.ch'
#include 'xbrowse.ch'


function Main()
   local oDlg, oBrw, oFont
   local aData
   local oFilter, oClear

    aData := {"voce1","voce2","voce3","voce4","voce5","voce6"}

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 700,500 PIXEL TRUEPIXEL FONT oFont

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aData AUTOCOLS HEADERS "Voce" ;
      CELL LINES NOBORDER AUTOSORT FOOTERS

   WITH OBJECT oBrw
      :aCols[ 1 ]:bFooter  := { || "Records : " + Str( oBrw:nLen ) }
      //
      :uBarGetVals   := Space( 10 )
      :bClrEdits     := { || { CLR_BLACK, CLR_YELLOW } }
      :lBarGetOnKeys := .t.
       :lGetBar       := .t.
      //
      :CreateFromCode()
   END

   @ 10, 20 BTNBMP oFilter PROMPT "Set Filter" SIZE 80,40 PIXEL OF oDlg FLAT ;
     ACTION ( xSetFilter( oBrw ), oBrw:SetFocus() )

   @ 10,100 BTNBMP oClear  PROMPT "Clear Filter" SIZE 80,40 PIXEL OF oDlg FLAT ;
      ACTION ( xClearFilter( oBrw ), oBrw:SetFocus() )
   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

   return nil


//--------------------------------------------------------------------------//
function xSetFilter( oBrw )

   local cFilter  := ""
   local oCol, c

   for each oCol in oBrw:aCols
      if !Empty( oCol:uBarGetVal )
         c  := Upper( AllTrim( oCol:uBarGetVal ) )
//        c  := "'" + c + "' $ Upper( aRow[" + LTrim( Str( oCol:nArrayCol ) ) + "] )"
        c  := "'" + c + "' $ Upper( cValToChar( aRow[" + LTrim( Str( oCol:nArrayCol ) ) + "] ) )"  // can be char,date,num
         if !Empty( cFilter )
            cFilter  += " .AND. "
         endif
         cFilter  += c
      endif
   next

   if Empty( cFilter )
      xClearFilter( oBrw )
   else
      cFilter  := "{ |c,aRow,oBrw| " + cFilter + " }"
      oBrw:bFilterExp  := &( cFilter )
      oBrw:ArrayIncrFilter( "dummy" )
      oBrw:Refresh()
      oBrw:SetFocus()
   endif

return .t.
//--------------------------------------------------------------------------//
function xClearFilter( oBrw )

   AEval( oBrw:aCols, { |o| If( o:oBarGet == nil, nil, o:oBarGet:cText := uValBlank( o:uBarGetVal ) ) } )
   if oBrw:nLen < Len( oBrw:aArrayData )
      oBrw:bKeyCount    := { || Len( oBrw:aArrayData ) }
      oBrw:Refresh()
   endif
   oBrw:SetFocus()

return .t.
//--------------------------------------------------------------------------//






 





How I can resolve ?
thanks
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests