Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Saving data when application exits

Posted on 2001-09-14
10
Medium Priority
?
241 Views
Last Modified: 2010-04-06
the aim is to save (to file) some data when the application exits.
 I want this to happen even if windows terminates the app when
 windows is shutdown. Perhaps I could catch the quit message sent
 to the app but I don't have any idea on how to do that.



   Thanks in advance

         Filipe Correia
0
Comment
Question by:filipecorreia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 180 total points
ID: 6483918
just assign a procedure to the onclosequery-event of your (main)-form,
where you can check, save or abort like

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var mresult : Integer;
begin
  if memo1.Modified then
  begin
    mResult := MessageBox(self.Handle,'Save before Quit?','Confirm',MB_YESNOCANCEL or MB_ICONQUESTION);
    case mResult of
      mrYes : If savedialog1.execute then
                memo1.lines.savetofile(savedialog1.filename);
      mrCancel : CanClose := False;
    end;
  end;
end;

meikl ;-)
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6484623
but... is the form's OnClose event trigered in case the main form is always hiden (by doing Application.ShowMainForm:=false) ? I think it isn't because when I put ShowMessage("hey"); in the OnClose event no message is shown when the app exits.


  Filipe Correia
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6484650
not the OnClose-event,
the OnCloseQuery-Event is meant

;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:lucika
ID: 6484892
If windows terminates the app when windows is shutdown app there comes the message WM_QUERYENDSESSION
0
 
LVL 6

Expert Comment

by:edey
ID: 6485012
But even in the case of a windows shutdown the OnCloseQuery event should still be fired - Kretzschmar is correct.

GL
Mike
0
 
LVL 1

Expert Comment

by:malsoft
ID: 6485912
Also, I was reading a few of the TI's on Borland's website the other day and they stated that if you do have a handler for the OnCloseQuery and set the value of CanClose to False, Windows shutdown can be halted.
0
 
LVL 3

Expert Comment

by:rondi
ID: 6486732
I'd put my code in the OnDestroy event handler.
It's sure to get called there, whatever the reason for
termination.

rondi
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6490613
I have an option in my app that terminates the app by doing:

      Application.Terminate()

When I do that the OnCloseQuery isn't trigered.
To solve this I tried subtitute this code by:

        Form1->Close();

and now everything seems to be working fine(I'll test it some more times).

Do you predict any sort of problem that may hapen by doing this?



rondi: I will try your suggestion but I haven't tried it yet.


    Filipe Correia
0
 
LVL 1

Expert Comment

by:DelRunner
ID: 6494844
I suggest to use the Close, rather than Terminate or HALT - as these are not polite ways to end your application !
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6499209
Hi

rondi: An EAccessViolation happens if I use the OnDestroy event. I don't know why!

I'll use the onCloseQuery event. My app seems to be working ok until now.


  Thanks to you all

        Filipe Correia
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question