Page 1 of 1

FILTER code block problem

Posted: Mon Mar 04, 2019 3:02 pm
by Janko
Dear Roger,

I would like to filter array with content of variable cMAt which is a result of DCSLE. Bellow is the ilustration of my intentions, of course, it is not working in presented form.

Code: Select all

LOCAL bFlt:={|a| (alltrim(upper(cMat))) $ a[2]}

@0,0 DCSLE cMat SIZE 30,1  DATALINK {||oBrowse:refreshAll()}
 
@ 2,0 DCBROWSE oBrowse DATA arr SIZE 100,25 ;
      PRESENTATION dc_BrowPres()  FIT     FILTER bFlt 

…..
…..
Any hint appreciated.
BR Janko

Re: FILTER code block problem

Posted: Mon Mar 04, 2019 4:34 pm
by rdonnay
Put some debugging in your code block to see the data as it is being evaluated :

The debug window will show the contents of a[2] and x for each row of the browse.

Code: Select all

LOCAL bFlt:={|a,x| x := (alltrim(upper(cMat))), (wtf x,a[2]), x $ a[2]}

Re: FILTER code block problem

Posted: Tue Mar 05, 2019 3:07 am
by Janko
Dear Roger,

I've prepared a small demo. Without FILTER it Works normal, after involving FILTER in DCBROWSE an error is generated
but I can not localize it.

I'd appreciate your suggestions.

BE Janko

Re: FILTER code block problem

Posted: Tue Mar 05, 2019 7:41 am
by rdonnay
I am still trying to figure out why it errors when cMat is initialized to an empty value.

I will work on this today.

A workaround for you is to initialize cMat := 'A'

Re: FILTER code block problem

Posted: Tue Mar 05, 2019 7:50 am
by rdonnay
Here is a fix that will work for you:

Code: Select all

LOCAL bFlt:={|a,x| x := (alltrim(upper(cMat))), Empty(x) .OR. x $ a[2]}

Re: FILTER code block problem

Posted: Tue Mar 05, 2019 9:59 pm
by Janko
Dear Roger,

yes, the solution is logical and it works.

I would ask you also for an advice: how to refresh (repaint) oBrowse after each key stroke.
WHEN clause, DATALINK only do it after changin focus to oBrowse. I need refreshing after any change of cMat.

Thanks in advance
Janko

Re: FILTER code block problem

Posted: Wed Mar 06, 2019 5:53 am
by rdonnay
This code prevents an error if the data entered in the DCGET is not found in the array.

Code: Select all

cMat := Space(30)
 @0,0 DCGET cMat PICTURE '@!' ;
    KEYBLOCK {|n,x,o|o:GetData(),FilterBrowse(n,oBrowse,arr,cMat,o)}


STATIC FUNCTION FilterBrowse( nKey, oBrowse, arr, cMat, oGet )

LOCAL nFound := AScan(arr,{|a|Alltrim(cMat) $ a[2]}), lStatus := .t.

IF nKey < 97 .OR. nKey > 122  // A-Z
  RETURN .t.
ENDIF

IF nFound > 0 .AND. !Empty(cMat)
  oBrowse:goTop()
  oBrowse:forceStable()
  oBrowse:refreshAll()
ELSE
  lStatus := .f.
ENDIF

RETURN lStatus

Re: FILTER code block problem

Posted: Wed Mar 06, 2019 10:42 am
by Janko
Dear Roger,
yes, yes it works perfect. Thank you very much.

Kind regards
Janko