FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour class xbrowse: suggestion for improvement
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM

class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 01:06 PM
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 (fw): Select all Collapse
        
 // 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
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 08:55 PM
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: class xbrowse: suggestion for improvement

Posted: Sat Jun 01, 2019 09:34 PM
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 (fw): Select all Collapse
#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 (fw): Select all Collapse
   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 )
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 12:32 AM

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.

Regards



G. N. Rao.

Hyderabad, India
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 01:45 AM

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.

Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: class xbrowse: suggestion for improvement

Posted: Sun Jun 02, 2019 04:19 AM

Implemented in FWH 1905

Regards



G. N. Rao.

Hyderabad, India
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM

Re: class xbrowse: suggestion for improvement

Posted: Mon Jun 03, 2019 11:56 AM

Thank you!

Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF

Continue the discussion