home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------
- //
- // Seeker.cc -- Incremental search custom control
- //
- //
- // Visual dBASE Samples Group
- //
- // $Revision: 1.1 $
- //
- // Copyright (c) 1997, Borland International, Inc.
- // All rights reserved.
- //
- //------------------------------------------------------------------------
- //
-
- CLASS Seeker( oCont, cName ) of Entryfield( oCont, cName ) CUSTOM
-
- protect lNear, lExact, lFound, lRefresh, nMaxPos
- protect seekRowset
-
- // Set stock properties
- this.selectAll := true
- this.value := ""
-
- // Custom properties
- this.rowset = null // Set to override form.rowset
- this.tabAfter = 0 // Automatically tab after typing N chars
- this.seek = this.xSeek
-
- // Internal properties
- this.lNear = ( SET( "NEAR" ) == "ON" )
- this.lExact = ( SET( "EXACT" ) == "ON" )
- this.lRefresh = this.form.RefreshAlways
- this.lFound = true
- this.nMaxPos = 0 // Max position of cursor in entryfield
-
- FUNCTION onGotFocus
- if form.rowset == null // Xbase settings
- this.lNear = ( SET( "NEAR" ) == "ON" )
- this.lExact = ( SET( "EXACT" ) == "ON" )
- this.lRefresh = form.RefreshAlways
- set near on // To do incremental matching
- set exact off // To return FOUND() .T. on substring match
- form.RefreshAlways = .t.
- this.seek = this.xSeek // Use method with Xbase SEEK()
- else
- // For OODML, use findKeyNearest(), which always does a
- // partial key match (like EXACT OFF)
- this.seek = this.oSeek
- // Assign protected object reference to either form's rowset
- // or control's rowset
- this.seekRowset = iif( this.rowset == null, form.rowset, this.rowset )
- endif
- this.lFound = .t.
- this.nMaxPos = 0
-
- FUNCTION key( nChar, nPosition )
- if nextkey() # 0
- // Wait until there are no keystrokes pending, and...
- RETURN ( nChar # 255 ) // ...ignore keystroke if special key
- endif
- if nChar == 255
- if .not. empty( this.value ) .and. ;
- ( this.lFound .or. nPosition <= this.nMaxPos )
- this.lFound = this.seek()
- endif
- if this.tabAfter > 0
- // Stuff tab if position is greater than tabAfter
- nChar = iif( nPosition > this.tabAfter, 9, 0 )
- else
- nChar = 0
- endif
- this.nMaxPos = max( nPosition, ;
- min( this.nMaxPos, len( trim( this.Value ))) )
- else
- if nChar >= 32 .and. nChar < 255
- // Stuff special key to refire key event
- keyboard "{255}"
- endif
- endif
- RETURN nChar
-
- FUNCTION xSeek
- local lRet
- lRet = seek( this.normalizedValue() )
- if eof() // Always move record pointer to real record
- goto bottom
- endif
- RETURN lRet
-
- FUNCTION oSeek
- local lRet
- lRet = this.seekRowset.findKeyNearest( this.normalizedValue() )
- if ( this.seekRowset.endOfSet )
- this.seekRowset.next( -1 )
- endif
- RETURN lRet
-
- FUNCTION normalizedValue
- RETURN upper( trim( this.value ))
-
- FUNCTION onLostFocus
- if form.rowset == null
- if .not. this.lNear
- set near off
- endif
- if this.lExact
- set exact on
- endif
- form.RefreshAlways = this.lRefresh
- endif
-
- ENDCLASS
-
-
-
-
-