Page 1 of 1

class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 1:06 pm
by tiaofw
I have for some time been aware that when using the RddIncrFilter method, it made a preexisting filter be lost when changing the search filter, I made a change in the class I would like to share to check if it is the best solution and suggest that they implement it future versions of fwh.

Here is the suggested change that will cause a pre-existing filter to be maintained even if another filter is configured:

Code: Select all

        
 // new code
         if Empty( cExpr )
            cFilter     := if(!empty(dbfilter()) .and. '.and. WildMatch'$dbfilter(), alltrim(substr(dbfilter(), 1, ;
                           at('.and. WildMatch', dbfilter()) - 1 )), if(empty(dbfilter()), '!deleted()', dbfilter())) // '!deleted()'
            oBrw:gotop()

         elseif ::lSeekWild
   #ifdef __XHARBOUR__
            cFilter     := if(!empty(dbfilter()) .and. '.and. WildMatch'$dbfilter(), alltrim(substr(dbfilter(), 1, ;
                           at('.and. WildMatch', dbfilter()) - 1 )), dbfilter()) // '!deleted()'
            cFilter     := cFilter + if(!empty(dbfilter()), ' .and. ', '') + 'WildMatch("*' + Upper( Trim( cExpr ) ) + '*",' + cKey + ')'
   #else
            cFilter     := dbfilter() + if(!empty(dbfilter()), ' .and. ', '') + 'HB_WildMatch("*' + Upper( Trim( cExpr ) ) + '*",' + cKey + ')'
   #endif
         else
            cFilter     := if(!empty(dbfilter()) .and. '.and. WildMatch'$dbfilter(), alltrim(substr(dbfilter(), 1, ;
                           at('.and. WildMatch', dbfilter()) - 1 )), dbfilter()) // '!deleted()'
            cFilter     := cFilter + if(!empty(dbfilter()), ' .and. ', '') + cKey + '="' + Upper( Trim( cExpr ) ) + '"'
         endif
// end new code

/*

// old code

if Empty( cExpr )
            cFilter     := '!deleted()'
         elseif ::lSeekWild
#ifdef __XHARBOUR__
            cFilter     := 'WildMatch("*' + Upper( Trim( cExpr ) ) + '*",' + cKey + ')'
#else
            cFilter     := 'HB_WildMatch("*' + Upper( Trim( cExpr ) ) + '*",' + cKey + ')'
#endif
         else
            cFilter     := cKey + '="' + Upper( Trim( cExpr ) ) + '"'
         endif
*/
// end old code
 


Any improvements your colleagues might suggest or a better solution, feel free to suggest.

Thanks

Re: class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 8:55 pm
by nageswaragunupudi
I have for some time been aware that when using the RddIncrFilter method, it made a preexisting filter be lost when changing the search filter,
This is an issue.
We can not use dbfilter() to combine the existing filter because, if the existing filter contains local variables, evaluation of such filter results in a runtime error.

Re: class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 9:34 pm
by nageswaragunupudi
With your code, two problems are found.
1) When the filter is cleared backspace, the filter is not reset.
2) Most important is the runtime error when the existing filter contains local variables.

Please try this sample:

Code: Select all

#include "fivewin.ch"

function Main()

   local cState := "NY"

   USE CUSTOMER

   SET FILTER TO FIELD->STATE = cState
   GO TOP

   XBROWSER "CUSTOMER" AUTOSORT SETUP ( ;
      oBrw:lIncrFilter := .t., ;
      oBrw:lSeekWild   := .t., ;
      oBrw:cFilterFld  := "FIRST" )

return nil
 
When we press a key, we get this runtime error

Code: Select all

   Time from start: 0 hours 0 mins 6 secs 
   Error occurred at: 02-06-2019, 03:00:06
   Error description: Error BASE/1003  Variable does not exist: CSTATE

Stack Calls
===========
   Called from: GIT\xbrowse.prg => TXBROWSE:RDDINCRFILTER( 7005 )
   Called from: GIT\xbrowse.prg => TXBROWSE:RDDINCRSEEK( 6896 )
   Called from: GIT\xbrowse.prg => (b)TXBROWSE_SETRDD( 5427 )
   Called from: GIT\xbrowse.prg => TXBROWSE:SEEK( 8434 )
   Called from: GIT\xbrowse.prg => TXBROWSE:KEYCHAR( 3593 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
 

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 12:32 am
by nageswaragunupudi
We can not use DBFILTER() and that is proved in the above sample.
DBFILTER() returns the current filter string. What we need is the current filter codeblock. FWH1905 provides a new function FW_DBFILTERBLOCK() which returns the current filter codeblock.

Using this new function FWH1905 implements what you are looking for. Incremental filters are in addition to the existing filter. Present filters are not lost.

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 1:45 am
by tiaofw
Thanks for the answer.

Can you implement a better solution for the future version of Fivewin?

I think you understood the problem well.

I do not feel able to change the class.

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 4:19 am
by nageswaragunupudi
Implemented in FWH 1905

Re: class xbrowse: suggestion for improvement

Posted: Mon Jun 03, 2019 11:56 am
by tiaofw
Thank you!