Thursday, October 9, 2014

Automate Save State Feature in Firemonkey

One of the many exciting new features of Delphi XE7 is the Save State in Firemonkey.
The FireMonkey Save State feature allows you to save data describing the state of the application before it closes. The Save State data can be used to recover the state after the application is restarted.
This is a very cool feature but the way in which you save and restore the data is not so refined (for more info see this ).
What happen if I need to save 10,15 or more components? I need to specify the save and the restore for each one.
So I decided to write a class helper to automate this process!
Using JSON serialization all the components of type TFMXObject are saved. In particular is stored the Data property.

You can find the demo in my github repository .

This is a snippet of the demo

uses SaveStateHelper;

procedure TForm1.FormCreate(Sender: TObject);

procedure TForm1.FormSaveState(Sender: TObject);

I hope you enjoy it!!


  1. Would be wonderful if it worked, but unfortunately not in Android - so whatt the point ?
    C++ Builder XE8.

    1. which version of Android tested? It seems not working well on Android 5.0 and up. I have to investigate, but probably has changed something in the app-lifecycle because the FormSaveState event is not fired anymore when app shut-down.

  2. It also does not work for me, but the save state event is fired.

  3. Doesn't work also for me.
    Delphi XE8 on Android 4 and also on android 5.
    OnSaveState don't fire. I put the procedure in OnFormClose so now it fires, but anyway i found NO data reading the State (both leaving empty the Path and name and valorizing them.
    Compiling in Windows it works fine.

  4. It works great on Android. If you kill the Android app then it doesn't persist the data unless you specify a storage path. You have to wait for the activity to get pushed out of memory.

    The easiest way to test it is to go into Developer Options and enable "Don't keep activities" (toward the bottom, under Apps). That will cause the activities to get removed automatically as soon as you switch out of them.

  5. I use a lot of tframe containing label + edit and then it did not work. I modified it slightly and now it does work. I will send to your gmail so you can decide if it is useful.