4

I have been trying to write out data to storage when the form closes or the application terminates and have NOT been successful.

I first tried from the Form unit

procedure TForm1.FinalizeObject;
begin
inherited;
SaveData;
end; 

and

procedure TForm1.FinalizeObject;
begin 
 SaveData;  
 inherited;
end; 

neither of these attempts worked, therefore I rrearranged my code and tried it from the project’s unit

procedure TApplication.ApplicationClosing;
begin 
 SaveData; 
 inherited;
end; 

and

procedure TApplication.ApplicationClosing;
begin 
 inherited; 
 SaveData;
end; 

I have a w3_showmessage as the first line of SaveData, and it never gets called ever....so, if i can verify that one of these 4 methods is triggered, i could use one of them

What am i doing wrong? Thanks

JakeSays
  • 2,048
  • 8
  • 29
  • 43
  • 2
    I believe neither FinalizeObject nor ApplicationClosing are called when the browser window is closed. Don't know about on-device applications, though (but would suspect the same). – gabr Jun 27 '12 at 10:13
  • As I stated, neither of these are called when i close my app down – JakeSays Jun 28 '12 at 17:08
  • Well, I was just confirming this :) I sent your question to the author of Smart Mobile Studio but he's on vacation until next week ... – gabr Jun 28 '12 at 17:35
  • Hi gabr, i got an answer back from them. Because my SaveData line has a w3_showmessage as the first line, then the rest of the routine isn't called. You can't use a w3_showmessage in the finalizeObject or ApplicationClosing methods. – JakeSays Jul 05 '12 at 18:48
  • Ah, interesting! I think you should write an answer to your own question ... – gabr Jul 05 '12 at 19:04

1 Answers1

2

As of writing, Smart exposes two new events in the application object:

  • OnUnload
  • OnBeforeUnload

These will make it easier to handle shutdown sequences. The smart javascript bootstrap also calls application.terminate() automatically now, so your code should work fine.

Jon Lennart Aasenden
  • 3,920
  • 2
  • 29
  • 44