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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check file saved before exit app.

Status
Not open for further replies.

MerryMadDad

Programmer
Dec 11, 2001
47
GB
Hello all,

Can anyone tell me how to run a bit of code that will check if a file has been saved when the user clicks on the X at the top right of the app screen. I got this to work Ok when using File | Exit but not with the application close button.

Thanks for any help
 
Hi Mary.., it is easy,..

The type TForm has implemented the event OnClose (if you focus your Form1, you can see this in object inpector window, where you have to click to Events). This event is activated on the application close. So, double click on the empty field on the right of text OnClose and write your desired code.

Jenda
 
You can also use the OnCloseQuery form event. The following is an excerpt from the Delphi help:

Use OnCloseQuery to specify the conditions under which the form can close. An OnCloseQuery event handler contains a Boolean CanClose variable that determines whether a form is allowed to close. Its default value is True.

You can use an OnCloseQuery event handler to ask users if they are sure they really want the form closed immediately. For example, you can use the handler to display a message box that prompts the user to save a file before closing the form.


Hope this helps, Clive [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top