your customer and final user, is using by first time your application, write, add records, edit it, process data, etc. in a unafortunate moment, he need clear the content of one field (in a textbox control) in the current form. when he begin to clear the field, using the backspace key; and comes to start of field, the cursor leap in a previous field and he look that, not only is cleared the required field value!, this also clear other fields!. your user try undo it, but he can not do it. then, a famous question is  ask you: because this problem in you application?. you do'nt can say: "because it was made with vfp!"

this is a old problem (o will be a feature?) in foxpro and d-base applications, that work with textbox control. you have a set of fields in your form and press many, many, the backspace key in the last field, then you look at it, and you have a new and clear form.

to resolve the problem, in your textbox base class, add the following code in the keypress method:

lparameters nkeycode, nshiftaltctrl

*-- control when you are using a mask input
lcondicion = .f.
nselstart= this.selstart

*-- this is a validation when you are using a
*-- formatted control
if type("this.value")="c" and nselstart>0
	*-- obtains the control current value
	cvalue1 = alltrim(substr(this.value,1,nselstart))
	
	nlen = len(cvalue1)
	
	*-- get a empty formatted value using the control input mask
	cvalue2 = alltrim(transform(space(nlen),this.inputmask))
	
	*-- if the empty formatted value is equals to
	*-- control current value, you also need apply the feature!
	lcondicion = (cvalue1 == cvalue2)
endif

*-- if you're in the real selection start of value and
*-- the pressed key was the backspace key {127}, remove the key from buffer
if (nselstart<1 or lcondicion) and nkeycode=127
	nodefault
endif

now, run your form and press the backspace key. when the cursor comes to the begin of your control, it does not leap to another text controls.

this code is valid for texbox and combobox controls. the problem has been not detected in the editbox control.

Leave a Reply

Your email address will not be published. Required fields are marked *