Jump to content

Recommended Posts

Posted (edited)

Hello, I need advice from all of you. I know I am not the only one who has got these problems. Maybe someone has already solved it.

1.-How to handle undo and redo in code?

2.-What are the best strategies for handling it in the relational databases (InterBase and Firebird)?

best wishes, k.z.

Edited by skyzoframe[hun]

Share this post


Link to post
Posted (edited)
12 minutes ago, skyzoframe[hun] said:

Maybe someone has already solved it.

The Command Design Pattern (sourcemaking.com) is generally used for undo/redo operations.

 

Regarding databases: Not sure if you're looking for undo/redo or just transactions. Maybe this is relevant to you:

Managing Transactions (FireDAC) - RAD Studio (embarcadero.com)

Edited by Der schöne Günther

Share this post


Link to post

If there can be multiple users modifying the same database then this task becomes very challenging. 

  • Like 2

Share this post


Link to post
7 hours ago, skyzoframe[hun] said:

Hello, I need advice from all of you. I know I am not the only one who has got these problems. Maybe someone has already solved it.

1.-How to handle undo and redo in code?

2.-What are the best strategies for handling it in the relational databases (InterBase and Firebird)?

best wishes, k.z.

 

A classical way to achieve undo/redo is if your object can serialize itself, for example using XML or Json.   That way you can keep the last xxx modified versions of the object in a temporary folder on disk.

Share this post


Link to post
3 hours ago, A.M. Hoornweg said:

 

A classical way to achieve undo/redo is if your object can serialize itself, for example using XML or Json.   That way you can keep the last xxx modified versions of the object in a temporary folder on disk.

Very rare to find a scenario where this works well.  The serialised state can be huge.  And the asker here has a database to work with. You are going to serialise that in its entirety?

Share this post


Link to post
11 hours ago, skyzoframe[hun] said:

Thanks for the information. I will buy the book! 

There is a nice Delphi specific design patterns book as well.

 

https://www.amazon.com/dp/1789343240

 

For databases, I know interbase is supposed to be designed that it stores transactions as part of its structure, which makes it easier to roll back.

Share this post


Link to post

Best way WRT databases is generated SQL stored at client side or a change log stored in a table. But it could be tricky. Anyway the question is too broad to give concrete answers.

  • Like 1

Share this post


Link to post
Posted (edited)

I'm interested in all options because I don't know what the best solution would be.


hm... I stay in the database table.  I will use the unique ID of the database in negative ranges and make a copy of the row there. Before the line changes.

Also, I need a column to store the unique ID of the changed row. (which was in the positive range)
Also, I need a column that contains the user ID. because after logging out I need to delete the rows stored in the negative range.


Maybe I can solve the log with two triggers.


I don't know how it will work.

I will share the final result here.

Edited by skyzoframe[hun]

Share this post


Link to post
15 hours ago, David Heffernan said:

Very rare to find a scenario where this works well.  The serialised state can be huge.  And the asker here has a database to work with. You are going to serialise that in its entirety?

Certainly not! But if the Delphi object represents a document or record in a database, backing up old versions on disk is often possible.  A colleague of mine has written a reporting tool that does precisely this.

Share this post


Link to post
3 hours ago, skyzoframe[hun] said:

hm... I stay in the database table.  I will use the unique ID of the database in negative ranges and make a copy of the row there. Before the line changes.

Also, I need a column to store the unique ID of the changed row. (which was in the positive range)
Also, I need a column that contains the user ID. because after logging out I need to delete the rows stored in the negative range.

 

You might be interested in the Delta property of TFDQuery.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×