How would you handle a combo-box with Style set to "2 - Dropdown List"? In this case, the Valid fires whenever you pick an item, but doesn't prevent you from leaving the control. I guess there are other ways of designing the interface so this problem isn't run into, but it seems like odd behavior to me regardless.
Also, in your example (as in mine), I guess focus is still in the textbox after using the access key. However, the command button has the dotted line around it as if it had focus, too.
>>I've noticed the following problem in VFP 6 SP3. Can someone confirm it, especially in VFP 7? If you put NODEFAULT in the LostFocus method, there should be no way for the control to lose focus, right? It appears that if you press the access key / hot key of another control, you can move focus to that control.
>
>Yes, that's true, and how it works in 7.0. It is somewhat unexpected, I suppose, though not too surprising. The control doesn't actually lose focus, the click executes, but the focus remains on the textbox (see my example below). What you're trying to do is what the Valid() is designed for, however, and belongs in the valid.
>
LOCAL loForm AS FORM
>loForm = NEWOBJECT('MyForm')
>loForm.SHOW(1)
>
>DEFINE CLASS MyForm AS FORM
> ADD OBJECT MyTextBox AS MyTextBox
> ADD OBJECT MyButton AS MyButton WITH TOP = 30
>ENDDEFINE
>
>DEFINE CLASS MyTextBox AS TEXTBOX
>
> VALUE = ""
>
> *!* Use valid instead of lostFocus
> PROCEDURE VALID
> DEBUGOUT PROGRAM() + " Value = " + THIS.VALUE
> IF EMPTY( THIS.VALUE )
> RETURN 0
> ENDIF
>
> ENDPROC
>
>*!* PROCEDURE LOSTFOCUS
>*!* DEBUGOUT PROGRAM() + " Value = " + THIS.VALUE
>*!* IF EMPTY( THIS.VALUE )
>*!* NODEFAULT
>*!* ENDIF
>
>*!* ENDPROC
>
>ENDDEFINE
>
>DEFINE CLASS MyButton AS COMMANDBUTTON
>
> CAPTION = "\<OK"
>
> PROCEDURE CLICK
> DEBUGOUT PROGRAM()
> ENDPROC
>
>ENDDEFINE
>