Thank you, Antonio.
But if the filter expression contained references to local or static variables you get an error:
Error BASE/1003 Variable does not exist: CRGZIMMERNR
How can you resolve this problem?
Thanks in advance
Otto
Otto wrote:Thank you, Antonio.
But if the filter expression contained references to local or static variables you get an error:
Error BASE/1003 Variable does not exist: CRGZIMMERNR
How can you resolve this problem?
Thanks in advance
Otto
LOCAL Gehrec1 := RECNO() , GehRec2
SKIP
Gehrec2 := RECNO()
SKIP -1 // When the first record matches or if no active filter , all is ok
IF RECNO() <> Gehrec1
GO Gehrec2
END
Basically the idea is that we are going to repaint the browse, and if the current record does not match the filter expression, then we skip it, so it is not displayed.
But as Frank said, isn't this redundant since the database RDD is already handling the filter? It seems to me that the xbrowse code will never even see a filtered record since the RDD won't ever return it.
//----------------------------------------------------------------------------//
METHOD DelRepos() CLASS TXBrowse
local lRepos := .f.
local cFilter, bFilter
if lAnd( ::nDataType, DATATYPE_RDD ) .and. ::nLen > 0
if ( Set( _SET_DELETED ) .and. ( ::cAlias )->( Deleted() ) ) ;
.or. ;
( ! Empty( cFilter := ( ::cAlias )->( dbFilter() ) ) .and. ;
Type( cFilter ) == 'L' .and. ;
! &cFilter )
( ::cAlias )->( dbSkip( 1 ) )
if ( ::cAlias )->( eof() )
( ::cAlias )->( DbGoBottom() )
endif
lRepos := .t.
endif
endif
return lRepos
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
METHOD DelRepos() CLASS TXBrowse
local lRepos := .f.
local rec1 , rec2
if lAnd( ::nDataType, DATATYPE_RDD ) .and. ::nLen > 0
if ( Set( _SET_DELETED ) .and. ( ::cAlias )->( Deleted() ) )
(::cAlias)->(DbSkip(1)) // If a filter is set , it will go to the first record that matches the filter expression
if ( ::cAlias )->( eof() )
( ::cAlias )->( DbGoBottom() )
endif
lRepos := .T.
else // Maybe the record doesn't match filter expression
rec1 := (::cAlias)->(Recno())
(::cAlias)->(DbSkip(1)) // If a filter is set , it will go to the first record that matches the filter expression
rec2 := (::cAlias)->(Recno())
(::cAlias)->(DbSkip(-1)) // If no filter is set , or if the original position matches the filter expression , it returns to his original position
if (::cAlias)->(Recno()) <> rec1
(::cAlias)->(DbGoto(Rec2))
lRepos := .T.
endif
endif
return lRepos
//----------------------------------------------------------------------------//
[/code fw]
nageswaragunupudi wrote:To start with, let me apologize for not looking at the posts during the last few days. Hence the delay in my response.
I wish the RDD handles it well. But unfortunately it does not. Though SET DELETED is ON, after we delete a record, the RDD does not move the record pointer. Similarly, if an edit invalidates a filter condition also, the RDD does not move the pointer. In both cases, it is the responsibility of the programmer to move the record pointer to ( next ) valid record. This can be done in many ways, but the most popular way is "DbSkip(1); if Eof(); DbGogottom(); endif". By the way. DbSkip( 0 ) also does not help.
This is the standard behavior of Clipper since the Summer 87, which faithfully implemented the behavior of Ashontate's DBase III. Naturally, Harbour and xHarbour provide the same behavior.
So, during a browse, if a record is deleted and SET DELETED is ON or a record is edited invalidating the filter condition, we have to manually write the repositioning code. We have to check for these situations every time and write the repositioning code in our application program for all browses. There were even many postings here by programmers, who did not know this behavior, seeking help. In all such cases they were advised to reposition the record pointer in the above manner.
Not only the deleted / invalid record continues to appear in the browse, subsequent navigation messes up the entire browse, without this repositioning logic.
I am a lazy programmer. If I have to repeat the same lines of code more than once, I would push it into a common function or into my libraries. I pushed this logic in to my copies of xbrowse and it was working satisfactorily to me. On this basis I suggested this enhancement and FWH adopted this.
The intention of this enhancement ( or headache ) was to avoid the need to keep repeating the same code by the programmer in all his browses and instead the xbrowse library to handle the situation automatically.
I did not encounter any problems because by habit since years, I do not use local or static variables ( or any variables ) or aliased expressions in my filter and index expressions.
I realized that this modification has become a great irritant to the programmers who use local / static variables in their filter expressions.
I propose revision of DelRePos() method as below:
- Code: Select all Expand view
//----------------------------------------------------------------------------//
METHOD DelRepos() CLASS TXBrowse
local lRepos := .f.
local cFilter, bFilter
if lAnd( ::nDataType, DATATYPE_RDD ) .and. ::nLen > 0
if ( Set( _SET_DELETED ) .and. ( ::cAlias )->( Deleted() ) ) ;
.or. ;
( ! Empty( cFilter := ( ::cAlias )->( dbFilter() ) ) .and. ;
Type( cFilter ) == 'L' .and. ;
! &cFilter )
( ::cAlias )->( dbSkip( 1 ) )
if ( ::cAlias )->( eof() )
( ::cAlias )->( DbGoBottom() )
endif
lRepos := .t.
endif
endif
return lRepos
//----------------------------------------------------------------------------//
Now, XBrowse deals both cases well, if the filter expression does not contain local/static variables. If it contains local/static variables, now the xbrowse does not complain through the irritating runtime error, but it does not help by repositioning the record pointer. The programmer has to himself write the repositioning logic in his program after re validating the filter expression.
Now I hope this method helps those who like to avail its benefit and does not come in the way of those who do not.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 96 guests