Showing posts with label ClassHelper. Show all posts
Showing posts with label ClassHelper. Show all posts

Sunday, June 25, 2017

Simple retry mechanism in Delphi

Hi all,
I want to share with you a nice unit that provide a retry pattern. How many times you want to execute some code and, if that method throws an exception, you want to retry executing it several times? For example when you try to connect to a service or network resource or a database. The operation was something that failed frequently enough that it was necessary sometimes to retry until it succeeded. With this unit you enable an application to handle transient failures by transparently retrying a failed operation.
Here is the RetryHelperU:
The snippet is very simple to understand: you have to specify the number of retries, the milliseconds between each retry and a TProc that represents the operation to do.
I also added this project to my Delphi Demos repository.
I hope it will be useful!

Thursday, October 9, 2014

Automate Save State Feature in Firemonkey

Hi!
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 http://docwiki.embarcadero.com/RADStudio/XE7/en/FireMonkey_Save_State ).
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);
begin
  LoadFormState;
end;

procedure TForm1.FormSaveState(Sender: TObject);
begin
  SaveFormState;
end;

I hope you enjoy it!!