class xbrowse: suggestion for improvement

class xbrowse: suggestion for improvement

Postby tiaofw » Sat Jun 01, 2019 1: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: Select all  Expand view  RUN

       
 // 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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: class xbrowse: suggestion for improvement

Postby nageswaragunupudi » Sat Jun 01, 2019 8: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
User avatar
nageswaragunupudi
 
Posts: 10654
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class xbrowse: suggestion for improvement

Postby nageswaragunupudi » Sat Jun 01, 2019 9: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: Select all  Expand view  RUN
#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  Expand view  RUN

   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: 10654
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class xbrowse: suggestion for improvement

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10654
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class xbrowse: suggestion for improvement

Postby tiaofw » Sun Jun 02, 2019 1: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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: class xbrowse: suggestion for improvement

Postby nageswaragunupudi » Sun Jun 02, 2019 4:19 am

Implemented in FWH 1905
Regards

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

Re: class xbrowse: suggestion for improvement

Postby tiaofw » Mon Jun 03, 2019 11:56 am

Thank you!
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 59 guests