1
votes

In my app I got JSON response from RESTServer. Then I convert them into Data Objects, store them in TObjectList and then bind the list to TListBindSourceAdapter for display.

I would like to save the TObjectList data to local storage. My question is: what is the best method to save it?

I tried to create a SQLite DB, I could save records into SQLite DB but it required to convert my TObjectList into DB records manually in code, and when I retrieve I need to convert it back to data object. It involves more development effort.

Or should I use SaveState? I could save local data as string using SaveState. I could try to use TJson.ObjectToJson to convert Data Object into JSON and save it. To do this, I could save the TObjectList into Array, store it into a data object and do convert to JSON. when retrieve I could convert back using TJson.JsonToObject.

Or is there any better method to do so? Is there a common method to save local data in Firemonkey? Is there something similar to State Management in Angular?

1
Local caching of the HTTP response could be another optionmjn42
If you need persistent storage then SQLite is okay to go. You may store from JSON directly to TDataSets.Marcodor
maybe you can save your json response directly? as you already parse them so no need to redo the procedure when you grab them from the diskzeus

1 Answers

1
votes

At last, I used SaveState to save my data to local. Since I tried and found using SaveState is much faster to develop and easier to develop.

The disadvantage of using saveState instead of saving into a local DB is, SaveState only happens when the application form closed, or in a mobile app, when the app deactivated. If the app in mobile app been killed directly instead of deactivating, the SaveState is not called and data may lose. Conversely, saving into local DB can be called manually anytime.