Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Way To Prevent a Form From Closing

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I should know this but are the Destroy and Unload methods too late in the process of a form closng to warn a user they have to save or cancel their changes? I think I used the Destroy method a long time ago, but wanted to ask the experts if there was a better way.

Auguy
Northwest Ohio
 
Yes, Queryunload. But if you have a close button doing Thisform.Release() it won't help alone. You better also use the Closable property to let the close button (X upper lright corner) look disabled. Still Release() does release the form, so you need to check in the release event:

Code:
   Procedure Release()
      If Not This.Closable
         Nodefault
      EndIf
   EndProc

Then you have a form that respects the Closable property in GUI (disabling the close button of the control box) and in code.

I'd rather recommend a mechanism that when the reason of the form close is a computer shutdown does automatically save or revert data changes and allows closing. You can react correctly by checking the Form.ReleaseType property.

Bye, Olaf.
 
Olaf,

I'd rather recommend a mechanism that when the reason of the form close is a computer shutdown does automatically save or revert data changes and allows closing.

Or, better still, prompt the user to save, revert or cancel ("cancel" means don't close the form, which in turn will signal to Windows not to proceed with the shutdown).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike and Olaf, thanks. Good info as always and I was planning on using form.closable on some way. This makes things a little clearer.

Auguy
Northwest Ohio
 
Worked great, I just set up a FormClose method that I call from both the queryunload method and my Exit.click button method. Thanks again to both of you.

Auguy
Northwest Ohio
 
Mike, well, I wouldn't suggest doing something that would interrupt shutdown. Such a messagebox would be okay with me, but the default answer should not be cancel, but either save or revert (eg Yes or No to the corrsponding question) and I would use the timeout.

In fact Shutdown, that is Shutdown of the computer, not only the app, does even kill processes not responding, therefore you should decide a standard option of save or revert and not cancel. Or else the shutdown might even do harm to data, as you neither saved nor reverted what VFP has in it's cursor buffers. It would normally work as a revert, but you never know.

Bye, Olaf.
 
Olaf,

I don't disagree with that. I usually set the default to Save. I've never done a timeout, but I can see why it would be a good idea. In that case, I'd set the default to Revert, on the basis that if the user is no longer present, a Save might cause validation errors that the user couldn't deal with.

I always test to see if there are unsaved edits before asking if they want to save. If the user hasn't changed anything, it's annoying (and irritating) to ask if you want to save your changes. I expect you do that as well.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Yes Mike,

an app doesn't need to ask if it doesn't find anything in the buffer, eg GetNextmodifed(0) returns 0 for each alias in question. I use dataaccess objects that have a ischanged() method, but it boils down to checking getnextmodified() in the normal cases.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top