KeyPress Method
Class: tsifcombo
Expand/Collapse source code of procedure KeyPress Source Code
LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lnRecNo

IF BITAND(4, nShiftAltCtrl) == 4
	*- the Alt key is pressed
	RETURN
ENDIF

IF INLIST(nKeyCode, 4, 19) OR;
	(INLIST(nKeyCode,52, 54) AND BITAND(1, nShiftAltCtrl) == 1) OR ;
	(INLIST( 2, 26) AND BITAND(2, nShiftAltCtrl) == 2) OR ;
	nKeyCode = 127
	*- left, right arrow
	RETURN
ENDIF

lnRecNo = RECNO(this.cAlias)

DO CASE
  CASE nKeyCode = 24
  	*- down arrow
  	IF EMPTY(THIS.DisplayValue)
  		*- nothing there yet, so go to first record
  		GO TOP IN (this.cAlias)
  	ELSE
  		IF !EOF(this.cAlias)
  			*- not at end of file, so go to next record
  			SKIP IN (this.cAlias)
  		ENDIF
		IF EOF(this.cAlias)
			GO BOTTOM IN (this.cAlias)
		ENDIF
  	ENDIF
  CASE nKeyCode = 5
    *- up arrow
  	IF EMPTY(THIS.DisplayValue)
  		*- nothing there yet, so go to first record
  		GO TOP IN (this.cAlias)
  	ELSE
  		IF !BOF(this.cAlias)
  			*- not at beginning of file, so go to previos record
  			SKIP -1 IN (this.cAlias)
  		ENDIF
		IF BOF(this.cAlias)
			GO TOP IN (this.cAlias)
		ENDIF
  	ENDIF

  *- changed to allow any ASCII character between 32 - 126
  *-- Valid chars include letters, digits, spaces, and apostrophes
  CASE BETWEEN(nKeyCode, 32, 126)	&& OR BETWEEN(nKeyCode, 97, 122) OR ;
       								&& BETWEEN(nKeyCode, 48, 57) OR ;
       								&& BETWEEN(nKeyCode, 33, 42) OR ;
       								&& nKeyCode = 32 OR nKeyCode = 64 OR nKeyCode = 94    
    *-- Build the internal search string
    this.cSearchString = this.cSearchString + CHR(nKeyCode)
  OTHERWISE
    RETURN
ENDCASE

*-- Cancel the default action. NODEFAULT is necessary to prevent
*-- two copies of the character from being displayed in the combo 
*-- since we control the DisplayValue property manually. 
NODEFAULT

*-- Do the SEEK(), unless user pressed up or down arrow keys (keys 5 and 24)
IF nKeyCode # 5 AND nKeyCode # 24 AND !EMPTY(this.cSearchString)
  =SEEK(UPPER(this.cSearchString), this.cAlias, this.cTag)
ENDIF

IF (EMPTY(this.cSearchString) OR EOF(this.cAlias)) AND nKeyCode # 5 AND nKeyCode # 24
	*-- SEEK() failed
	IF lnRecNo > RECC(this.cAlias)
		GO TOP IN (this.cAlias)
	ELSE
		GO lnRecNo IN (this.cAlias)
	ENDIF
    *-- If entries are permitted that are not in the list, 
    *-- then set the DisplayValue property to the value of the
    *-- search string. Otherwise, remove the character just typed
    *-- from the search string.
    IF !this.lLimitToList
      this.DisplayValue = this.cSearchString
      this.SelLength = 0
    ELSE
      *-- Do not add char just typed to search string
      this.cSearchString = LEFT(this.cSearchString, ;
                                LEN(this.cSearchString) - 1)
    ENDIF
ELSE
  *-- SEEK() was succsssful, so fill in the DisplayValue
  this.DisplayValue = EVAL(this.cField)
  *-- Select entire string
  this.SelLength = LEN(this.DisplayValue)
ENDIF

*-- Position cursor at end of string
this.SelStart = LEN(this.cSearchString)