>Hola everyone!
>
>Can anyone tell me waht I need to do, to cancel a Valid event whe the user press the Esc Key or with a Click at a command button
>
>Im a newbbie, so dont desesperate with my silly questions.
>
>Thanx in advance
>
>Saludos from Cancun
Hello, Roberto
This problem was discussed here, and Jim Booth suggested the shortest solution, so I just repeat his reply here
********************************************
* From Jim Booth solution
There are a million ways to deal with this, the simpleest is to set the Cancel property of your Cancel button to .T. (which makes
clicking that button equivalent to pressing the escape key). Then start off all Valid code with;
IF LASTKEY() = 27 && escape
RETURN .T.
ENDIF
That's it, no more no using sys(1270) to find out the name of the object the mouse is over, no fancy coding all over the place. You
simply make the Cancel button the Escape button and the check in your valid code to see if the user pressed escape. This not nly
works but is eliminates the question of "How do stop the user from closing my form with the escape button?" Because pressing the
escape key is the same as clicking teh cancle button and pressing escape will run the click code of the cancel button and do all those
thing you've set up for cancelling.
end of Jim Booth solution******************
Also, if you want to know about other approaches, there was an article "PEM for your base classes" by Doug Hennig in February's 1997 FoxTalk. with the solution on the base classes
level 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.
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