Forum > FPSpreadsheet

Undo/redo

<< < (2/2)

dbannon:
Its not hugely hard to implement yourself. Its just a case of working what are the changes you want to 'undo' and storing a representation of them on a circular buffer.

I made a undo/redo unit for KMemo, https://github.com/tomboy-notes/tomboy-ng/blob/master/source/tbundo.pas - its almost certainly no direct use to you unless you use KMemo but it  might give you a few ideas to follow up on. KMemo, being a text thingo, is text focused.

Sounds like you will want to record control positions, just a case of, perhaps, making a record that contains the name of a control, its position. Poke that record into the buffer each time someone moves moves things. On undo, Pop each record back out and restore the control to the position recorded in the popped record.

Obviously, some housekeeping is required, you need to manage the most recent and oldest record, decide when to throw away the oldest to make room for a new one. And probably implement some sort of delay before recording a new record to make sure the user has finished moving ...

Davo

Thaddy:
Dead giveaway:
It is a stack. (or basicallly a singly linked list)

If you can't write a stack you are not a programmer.( Yet 8) :D)

Happy new year!

p.s.  I propose you order https://www.amazon.com/Tomes-Delphi-Algorithms-Data-Structures-ebook/dp/B007FKB0EI although that may seem a blatant advert, it is not! all example code compiles with FreePascal.
There are many more links about algorithms and data structures. You will NEED that knowlege at some point.
Use a TStack<T>............

Navigation

[0] Message Index

[*] Previous page

Go to full version