Mike,
I wish I saw that thread earlier today, because I was working on the exact same problem. There is a FAQ by John Koziol, but Cetin Basoz suggested very short way to implement it.
CancelValidation method of the form
local llReturn
llReturn = lower(justext(sys(1272,sys(1270)))) = "cmdcancel" and mdown()
return m.llReturn or lastkey()=46 or thisform.releasetype = 1
textbox.valid()
local llReturn
llReturn = .t.
if not thisform.cancelvalidation()
continue your logic
endif
return m.llReturn
I'm writing this from my head, but hopefully you'll get the idea.
>Hi,
>
>I have a form with several controls on it. There is a "Cancel" button that I want to be able to select at anytime to close the form and discard all changes. The problem is that if a control has focus and has valid code in it that prevents it from losing focus, the "Cancel" button is useless. Try the following code:
>
>PUBLIC oMyform
>oMyform=NEWOBJECT("form1")
>oMyform.Show
>RETURN
>
>DEFINE CLASS form1 AS form
>
> ADD OBJECT cmdCancel AS commandbutton WITH ;
> Top = 10, ;
> Left = 256, ;
> Height = 24, ;
> Caption = "Cancel"
>
> ADD OBJECT text1 AS textbox WITH ;
> Left = 10, ;
> Top = 10, ;
> Width = 100
>
> PROCEDURE text1.Valid
> RETURN !EMPTY(this.value)
> ENDPROC
>
> PROCEDURE cmdCancel.Click
> thisform.Release()
> ENDPROC
>
>ENDDEFINE
>
>
>If you enter the textbox and try to immediately Cancel, you cannot until you actually type something in the textbox!
>
>Anyone know how to get around this annoying behavior? VFP9?
>
>TIA
>
>Regards,
>
>Mike
If it's not broken, fix it until it is.
My Blog