FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Cambios en xBrowse
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Cambios en xBrowse
Posted: Tue Apr 14, 2015 09:17 PM
Antonio / Daniel

He realizado cambios en la función DolphinSeek del método SetDolphin porque no funcionaba correctamente.
Aquí los cambios
Code (fw): Select all Collapse
static FUNCTION DolphinSeek( c, oBrw, cQryWhere )

   local oQry        := oBrw:oMySql
   local nStart
   local uData, nNum, lRet
   local cSortOrder

   static aLastRec := {}

   if oBrw:lIncrFilter
     //  DEFAULT oBrw:cFilterFld := TOken( oQry:cOrder, , 1 )
         oBrw:cFilterFld := TOken( oQry:cOrder, , 1 )  //Le quite el DEFAULT porque no cambiaba orden al dar cllick en otra columna

      if Empty( oBrw:cFilterFld )
         return .f.
      endif

     // if Empty( c ) 
       If Len(c)=1 //Al usar BACK SPACE no colocaba el puntero en el primer registro
         c     := cQryWhere
      else
         c     := If( Empty( cQryWhere ), "", "(" + cQryWhere + ") and " ) + ;
                  Lower( oBrw:cFilterFld ) + " like '" + ;
                  If( oBrw:lSeekWild, "%", "" ) + ;
                  c + "%'"
      endif
      oQry:SetWhere( c, .t. )
      oQry:GoTop()
      return ( oQry:LastRec() > 0 )

   endif

   if Empty( c )
      return .t.
   endif

   nNum = AScan( oBrw:aCols, {| o | !Empty( o:cOrder ) } )

   if nNum < 1
      RETURN .f.
   endif

   cSortOrder = oBrw:aCols[ nNum ]:cSortOrder

   if Len( c ) == 1
      aLastRec    := {}
   endif

   IF Len( aLastRec ) < Len( c )
      IF Len( aLastRec ) == 0
         nStart = 1
      ELSE
         nStart = oQry:RecNo()
      ENDIF
      AAdd( aLastRec, nStart )
   ELSE
//      ADel( aLastRec, Len( aLastRec ) )
//      ASize( aLastRec, Len( aLastRec ) - 1 )
      ASize( aLastRec, Len( c ) - 1 )
      IF Len( aLastRec ) == 0
         nStart = 1
      ELSE
         nStart = ATail( aLastRec )
      ENDIF
   ENDIF

 //  lRet  := ( oQry:Seek( c, cSortOrder, nStart - 1, oQry:LastRec(), .T., .T. ) != 0 )
       lRet  := ( oQry:Seek( c, cSortOrder, nStart, oQry:LastRec(), .T., .T. ) != 0 ) //con el -1 al pulsar un caracter no nro. en orden numérico, se cuelga.

return lRet


Tengo FWH1501 no se si ya lo han corregido.



Code (fw): Select all Collapse
 @0,0 xBrowse oBrw Of oDlg AUTOSORT DATASOURCE oQry COLUMNS "IDEMPL" //Si no coloco COLUMNS me carga todos los campos
 //oBrw:setdolphin(oQry,.F.)  de esta manera no funciona la búsqueda
 oBrw.... 
 oBrw:lIncrFilter:= .t.
  oBrw:lSeekWild:= .t.

  oCol:=oBrw:AddCol()
   oCol:bEditValue  := { || oEMPL:CODIGO }
   oCol:nHeadStrAlign := AL_CENTER
   oCol:cHeader:= "COD."
   oCol:nWidth:=30
   oCol:cSortOrder := "CODIGO"
   oCol:bLClickHeader:= {|| oBrw:GoTop() }
    
   oCol:=oBrw:AddCol()
   oCol:bEditValue  := { || oEMPL:NOMBRE } 
   oCol:nHeadStrAlign := AL_CENTER
   oCol:cHeader   := "NOMBRE Y APELLIDOS"
   oCol:nWidth:=223
   oCol:cSortOrder := "NOMBRE"
  oCol:bLClickHeader:= {|| oBrw:GoTop() }

   oBrw:aCols[1]:Hide() //Obligado a ocultarlo 

  REDEFINE SAY oBrw:oSeek PROMPT oBrw:cSeek ID 114 OF oDlg UPDATE PICTURE "@!"


Existe otra manera de evitar el COLUMNS ó oBrw:setdolphin(oQry,.T.,.T.,{"IDEMPL"})

Saludos,

Adhemar
Saludos,



Adhemar C.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Cambios en xBrowse
Posted: Wed Apr 15, 2015 08:42 AM
Suggestion-1
Code (fw): Select all Collapse
     //  DEFAULT oBrw:cFilterFld := TOken( oQry:cOrder, , 1 )
         oBrw:cFilterFld := TOken( oQry:cOrder, , 1 )  //Le quite el DEFAULT porque no cambiaba orden al dar cllick en otra columna

We retain DEFAULT. This is intentional, not a mistake and is consistent with incremental filter behavior of all other sources like dbf, array, ado, etc.

Normally, cFilterFld is to be provided by the programmer initially. DEFAULT is provided in case of omission of this. It is intended that re-sorting of the data by the user should not disturb the filter.

If and when the programmer wants to change the filter field, he may do it by oBrw:Seek( "" ), oBrw:cFilterFld := <newfld>.

Suggestion-2
Code (fw): Select all Collapse
   // if Empty( c ) 
       If Len(c)=1 //Al usar BACK SPACE no colocaba el puntero en el primer registro

Please reconsider.
Our code "if Empty( c )" works properly.

Suggestion-3:
Code (fw): Select all Collapse
//  lRet  := ( oQry:Seek( c, cSortOrder, nStart - 1, oQry:LastRec(), .T., .T. ) != 0 )
       lRet  := ( oQry:Seek( c, cSortOrder, nStart, oQry:LastRec(), .T., .T. ) != 0 ) //con el -1 al pulsar un caracter


Original code by Mr Daniel was to use nStart only but not nStart-1. I saw his post sometime back that Mr Daniel prefers nStart but not nStart-1.

Years back we noticed that the the binary search logic of oQry:Seek was ignoring the first record (i.e, record number nstart). I did not see the recent sources of dolphin. As a result, oQry:Seek was returning false when only the 1st record was containing the search term.

Probably Max( 1, nStart - 1 ) is better.
Anyway we test this again and make necessary changes.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Cambios en xBrowse
Posted: Wed Apr 15, 2015 12:20 PM

Thanks Mr. Rao

Regards,

Adhemar

Saludos,



Adhemar C.

Continue the discussion