Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to stop a form from closing
Message
From
14/03/2001 22:10:49
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00485131
Message ID:
00485159
Views:
12
Ken,
*!* Release() Method
IF NOT THISFORM.CleanUpAndExit()
  NODEFAULT
ENDIF

*!* QueryUnload Method
IF NOT THISFORM.CleanUpAndExit()
  NODEFAULT
ENDIF

*!* CleanUpAndExit() Method
LOCAL llOkToQuit
llOkToQuit = .T.
IF lSomeCondition
  THISFORM.cmd1.SetFocus()
  llOkToQuit = .F.
ENDIF
RETURN llOkToQuit



>Cindy - thanks for the quick reply. I created a test form using your suggestion but I must have missed something. Two problems occur. If I close the form using the X, the CleanUpAndExit method fires but the form closes anyway. If I click on a Command Button that triggers the CleanUpAndExit method and my test condition is false, I get "Allowed DO nesting level exceeded" error. My CleanUpAndExit method looks something like this:
>
>If lcondition = .t. && Don't close form
>thisform.cmd1.setfocus
>else
>thisform.release
>endif
>
>
>Thanks again for your help and patience.
>
>>Ken,
>>
>>There are two ways to close a form - by calling THISFORM.Release(), (often code in an Exit button) or by the X, which fires QueryUnload(). Ultimately you must make sure your test runs by either close method.
>>
>>The best thing to do is to make a custom method like CleanUpAndExit() and put your test to see if you want to close in there. In each of the Release() and QueryUnload() methods, call THISFORM.CleanUpAndExit().
>>
>>You might put CleanUpAndExit in your base form class, and also the calls to it. Then in each form put whatever code you want to run when you clean up.
>>
>>If you don't want to exit, return .F. from CleanUpAndExit and SETFOCUS to whatever control you need to.
>>
>>
>>>Is there a way to test for a condition (eg. unsaved changes) when a form is closed (ie. user clicks the close icon on top right of form), abort the closing of the form and reset focus to a control?
>>>Thanks.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform