class xbrowse: suggestion for improvement

Post Reply
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

class xbrowse: suggestion for improvement

Post 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
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: class xbrowse: suggestion for improvement

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: class xbrowse: suggestion for improvement

Post 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 )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: class xbrowse: suggestion for improvement

Post 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.
Regards

G. N. Rao.
Hyderabad, India
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: class xbrowse: suggestion for improvement

Post 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.
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: class xbrowse: suggestion for improvement

Post by nageswaragunupudi »

Implemented in FWH 1905
Regards

G. N. Rao.
Hyderabad, India
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: class xbrowse: suggestion for improvement

Post by tiaofw »

Thank you!
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
Post Reply