DCBROWSE ... FILTER

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

DCBROWSE ... FILTER

#1 Post by Tom »

Hi, Roger.

This feature is great and saves me a lot of work. :dance:

But there are two errors in there:

1. If the mouse wheel is used, "nWantSkip" in "DC_SkipArray" may lead to a value higher than the array length or lower than one. This causes "DC_SkipArray" to either postion the array pointer to the lenght of the array or to 1 (one). But both array values may not fetch the filter condition! So:

In "DC_SkipArray", behind "IF nPointer > Len(oBrowse:dataSource)" (about line 2920 in _DCXBROW.PRG) and behind "IF nPointer < 1" it should be:

a)
nPointer := Len(oBrowse:dataSource) // already in there, new:
DO WHILE !Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
nPointer --
ENDDO
b)

same at "IF nPointer < 1":

Code: Select all

nPointer := 1 // already in there, new:
DO WHILE !Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
  nPointer ++
ENDDO
2. If a new filter is set and the array element actually highlighted is not in this new filter, it stays there anyway.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCBROWSE ... FILTER

#2 Post by rdonnay »

Thanks Tom.

I'm working on a maintenance release (build 258).
I'll make sure this is in it.
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCBROWSE ... FILTER

#3 Post by rdonnay »

Here's what the new code looks like:

Code: Select all

FUNCTION DC_SkipArray( nWantSkip, oBrowse )

LOCAL nDidSkip, nPointer, nLastRec := Len(oBrowse:dataSource), ;
      nSavePointer

IF nLastRec = 0
  RETURN 0
ENDIF

nDidskip := nWantSkip

IF Empty(oBrowse:filter)

  IF oBrowse:descending
    IF oBrowse:arrayElement - nWantSkip < 1 // bof
      nDidSkip := -1 * (1 - oBrowse:arrayElement)
    ELSEIF oBrowse:arrayElement - nWantSkip > nLastRec // eof
      nDidSkip := -1 * (nLastRec - oBrowse:arrayElement)
    ENDIF
    oBrowse:arrayElement -= nDidSkip
  ELSE
    IF oBrowse:arrayElement + nWantSkip < 1 // bof
      nDidSkip := 1 - oBrowse:arrayElement
    ELSEIF oBrowse:arrayElement + nWantSkip > nLastRec // eof
      nDidSkip := nLastRec - oBrowse:arrayElement
    ENDIF
    oBrowse:arrayElement += nDidSkip
  ENDIF

ELSE

  nDidSkip := 0
  nPointer := oBrowse:arrayElement

/*
  IF nPointer == 0
    oBrowse:arrayElement := 1
    oBrowse:cargo[4] := oBrowse:arrayElement
    RETURN 0
  ENDIF
*/

  nSavePointer := nPointer
  IF oBrowse:descending
    nWantSkip *= -1
  ENDIF
  IF nWantSkip == 0
    nDidSkip := 0
  ELSEIF nWantSkip > 0
    DO WHILE nDidSkip < nWantSkip
      nPointer++
      IF nPointer > Len(oBrowse:dataSource)
        nPointer := Len(oBrowse:dataSource)
        DO WHILE !Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
          nPointer --
        ENDDO
        EXIT
      ELSEIF Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
        nDidSkip++
      ENDIF
    ENDDO
  ELSEIF nWantSkip < 0
    DO WHILE nDidSkip > nWantSkip
      nPointer--
      IF nPointer < 1
        nPointer := 1
        DO WHILE !Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
          nPointer ++
        ENDDO
        EXIT
      ELSEIF Eval(oBrowse:filter,oBrowse:dataSource[nPointer])
        nDidSkip--
      ENDIF
    ENDDO
  ENDIF
  IF nDidSkip == 0
    nPointer := nSavePointer
  ENDIF
  oBrowse:arrayElement := nPointer

ENDIF

IF oBrowse:arrayElement > Len(oBrowse:dataSource)
  oBrowse:arrayElement := Len(oBrowse:dataSource)
ENDIF
oBrowse:cargo[4] := oBrowse:arrayElement

RETURN nDidSkip

The eXpress train is coming - and it has more cars.

Post Reply