>I am converting a Clipper application to VFP 5.0. As I am rather new to Windows programming I guess this is a rather basic question.
>
>I would like to cancel and exit my form by pressing a Cancel button. However, if i am stuck in a Valid event, i am unable to do so until i enter a valid item in the field concerned. How do i solve this problem ?
>
>Thanks
>
>DESTINE
There was an article "PEM for your base classes" by Doug Hennig in February's FoxTalk. with the solution for this problem.
The general idea is in using of sys(1270) which points to object under the mouse cursor. The code in Valid method from that article:
local oObject
oObject = sys(1270)
if lastkey = 27 or (type('oObject') = 'O' and ;
type('oObject.lCancel') = 'L' and oObject.lCancel)
return .t.
endif
return this.Validation()
Note that commandbutton class has the custom property lCancel which determines is this button is used as Cancel button, and other classes have custom Validation method which performs the validation itself.
Sometimes I use just simplified version of this, without any custom methods and properties:
local oObject
oObject = sys(1270)
if lastkey = 27 or oObject.name = "MyCancelButton"
return .t.
endif
HTH
Nick
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison