Search code examples
delphimodel-view-controllerundo-redocommand-pattern

Data Entry screen updates Model objects in realtime, provides undo and redo, live updates to a model object using command pattern


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.


Solution

  • You should use followings patterns:

    • Model-GUI-Mediator
      -- synch between objects model and GUI control, so you are no limited by TDataset and DB-Aware controls. You can create object-aware controls from EVERY VCL controls.
    • Command
      --your ACTIONS on the objects model. Should be fired by Controllers.
    • Memento
      --saving internal state of Data Objects for implementing the Undo/ReDo behavior

    ASAP I'will post a simple example on my blog www.danieleteti.it