Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Run code ONLY when users pauses on keyboard input?
Message
De
22/10/2004 12:03:42
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
 
 
À
21/10/2004 11:46:59
Peter Brama
West Pointe Enterprises
Detroit, Michigan, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6
OS:
Windows '98
Database:
Visual FoxPro
Divers
Thread ID:
00953351
Message ID:
00953765
Vues:
14
Peter,
Here is some code that I use. I use that in an incremental search program I have. The key to what you are looking for is the inkey() function.

btw, I got some of this code from 1001 things you wanted to know about VFP.
	FUNCTION handelkey(toTxtObject)
		LOCAL llRet , loTxtObj, laEvent[1], lnSelStart, lcSofar, lnSelLength, llSeekSuccess, lnWait
		IF VARTYPE(toTxtObject)="O"
			loTxtObj = toTxtObject
		ELSE
			AEVENTS(laEvent,0)
			IF VARTYPE(laEvent[1]) = "O"
				loTxtObj = laEvent[1]
			ELSE
				RETURN .f.
			ENDIF 	
		ENDIF 
		
		WITH loTxtObj 
			llSeekSuccess = .f.
			lnSelStart = 0
			*// DEBUGOUT LASTKEY()
			IF INLIST(LASTKEY(),96,126) 
				=INKEY()
				llSeekSuccess = this.displaylist(loTxtObj)
			ELSE
				lnWait = INKEY(_incseek)
			        *** Handle backspace key
				IF LASTKEY() = 127 AND .SelStart > 0
					.SelStart = .SelStart - 1
				ENDIF	
				*** Get the value typed in so far
				lnSelStart = .SelStart
				lcSofar =  LEFT( .Value, lnSelStart ) 
				*// DEBUGOUT lcSofar 
				IF lnWait = 0
					llSeekSuccess = this.seekvalue(lcSofar)
				ELSE
					KEYBOARD (CHR(lnWait))
					llSeekSuccess = .f.
				ENDIF 	
			ENDIF 	

			IF llSeekSuccess 
				.Value = EVALUATE(this.csearchcursor+"."+this.csearchcolumn)
				this.lseekfailure = .f.
			ELSE 
				this.lseekfailure = .t.
			ENDIF 

			*** Highlight the portion of the value after the insertion point
			.SelStart = lnSelStart
			lnSelLength = LEN( ALLTRIM( .Value ) ) - lnSelStart 
			*// DEBUGOUT .SelStart, lnSelLength
			IF lnSelLength > 0
				.SelLength =  lnSelLength	
			ENDIF	
			RETURN llSeekSuccess
		ENDWITH
	ENDFUNC
>I have a form that has a textbox used for a search function. Currently, as the user keys information into the search box (tSearch), a KeyPress and Interactive change method controls processing. Certain function keys, such as left arrow, right arrow, enter, etc are processed specifically by the KeyPress method. The interactive change causes a rather large FILTER statement to display specific records in a grid elsewhere on the page based on the string entered in tSearch.
>
>The current function works well in that the grid constantly updates with only the relevant records that the "search" matches. The problem is, as the table grows, and now with the addition of having to filter on a 3rd field as well, the input is of course getting very sluggish... that is, the user can type 10 characters quickly and they appear at a slow rate as the filter updates with each.
>
>What I was considering was a way for the filter to NOT fire until the users keypress input pauses... that is, when they stop typing for a specified amount of time. This way, the user could key the whole search string and when they stop, the grid will update.
>
>Of course the easiest way would be to require an ENTER key or other specific key to actually do the search... the client would prefer not.
>
>I thought about using some sort of processing based of the SECONDS() command but not sure in what method I would place the code... that is, if I put it in KeyPress or InteractiveChange then that code will only fire WHEN they press a key, not when they STOP keying.
>
>Is there a way to do this that's not too extensive?
>
>Thanks
>
>Peter Brama
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform