Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set focus without using setfocus()
Message
From
28/02/2004 17:39:55
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00881299
Message ID:
00881822
Views:
33
Ok, imagine I have a text box which requires a valid 3 character user id to be entered.
Now the user mightn't know all the user codes so the valid event seems to me to be the place to validate the user's entry.
procedure valid
if seek(this.value, 'Usertable', 'UserId')
return .t.
else
local id
id= this.value
do form GetUserId with m.id
if empty(m.id)
return .f.
else
this.value= m.id
endif
endif

Now I've only invented this code as an example - the point is that if GetUserID does a setfocus() anywhere it blows up.
So how do I do the validation. I don't wan't to move this sort of validation to the form level because there may be other controls on the form which require a valid user id.

Lostfocus event creates a mess because all sorts of other code can fire and it doesn't seem to work anyway. Create a blank form with two textboxes. In the first put

procedure lostfocus
this.setfocus()

You can still freely tab between the two controls!





>In addition to the othe comments, you can use WHEN to prevent focus. One post suggested lostfocus instead of valid. Valids behavior is downstream restrictive. Also, if you have a clear button, and the cursor is in a control with a valid restriction, when you click the clear button, the valid code will fire.
>
>One method:
>
PROCEDURE MyText2.When
>RETURN !EMPTY(MyForm.MyText1.Value)
>or, if a complex valdidation is required, you could attach a flag property to the form "lOkayToAllowFocus" and set the validation in MyText1's LostFocus method:
>
PROCEDURE MyText1.LostFocus
>IF(SEEK(this.value,"MyDBF","MyDBFTag")
>   MyForm.lOkayToAllowFocus=.t.
>ELSE
>   MyForm.lOkayToAllowFocus=.f.
>ENDIF
>ENDPROC
>
>PROCEDURE MyText2.When
>RETURN MyForm.lOkayToAllowFocus
>ENDPROC
>
>>Setfocus() is not allowed to be called from a valid event of a textbox, editbox or spinner (there may be others, I don't know of). Not only that but setfocus() cannot be called if the valid event is anywhere in the call stack! I understand that doing a setocus within the same form or formset should not be allowed, but this is going too far!
>>
>>So, it's often the case in our system that a form is required to validate a users input. For example a form with an optionbuttons. If that form does a setfocus() anywhere then we get the usual error. So how on earth can I call a setfocus() (or do the programmatic equivalent) in a form that is separate to the form on which the valid() event is running??
Previous
Reply
Map
View

Click here to load this message in the networking platform