Hey Perry,
Very cool solution. THANKS.
Mike
>Mike,
>
>There is a very simple way to accomplish this. When the "Cancel" property of the "Cancel" button is set to .T., clicking on the button sets LASTKEY() to 27.
>
>So you surround all your valid code with:
>
>IF LASTKEY() <> 27
>...
>ENDIF
>
>The valid methods will not run if "Cancel" is clicked and the buttons "Cancel" property is set to .T.
>
>PF
>
>>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