views:

93

answers:

2

The well known Command pattern is used often when you want to implement a model with Undo/Redo capabilities. I am looking for a reference implementation (example) of a simple Delphi form that implements undo/redo.

From what I have seen, simple delphi data-entry forms with three Edit boxes, six memo boxes, and a few combo boxes and other simple edit controls, do not typically support Undo/Redo.

Has anyone seen a well designed delphi approach to multi-level undo/redo support for a complex model-view-controller design using a separate Delphi view (form), and model objects (data objects are updated synchronously with all edits to the form, and the validation and control logic is not embedded in the form, or in the model, but separated out.

It seems to me that if you didn't have to use MVC, and you needed to simply prototype a Delphi demo app that had no model or controller objects, that Undo/Redo of a pure simple Delphi "one-form-is-my-app" would be simpler to design, but it would get more complicated as you need to record and replay objects and synchronize them to Delphi form actions like TEdit.OnChange.

A: 

I'd probably base that on a ClientDataSet: that has undo capabilities (and if I remember correctly, it is pretty easy to implement redo with it as well).

Bonus: you can use data aware controls.

I have a feeling you are looking for some kind of ORM like behaviour.
At DelphiLive I will be speaking on doing a kind of ORM layer based on ClientDataSets; they are pretty cool.

--jeroen

Jeroen Pluimers
I was thinking of virtual-controls (but where do you find a virtual combo box, virtual editor, and so on).
Warren P
I like your idea. Of course I've had mixed luck with datasets.
Warren P
+2  A: 
Daniele Teti
Excellent. This helps because it's currently the model the existing code I am fixing up (not written by me) is using, so it really helps to know that someone else would have done exactly this. They called their class a "helper" but it's clearly a mediator, and their are Actions on the object fired by the Controller, and the Memento thing is an interesting one. For text (edit+memo controls) they used a Previous and Current value field in the memento object. It doesn't work right yet so it needs work.
Warren P