November 2019
Beginner to intermediate
674 pages
15h
English
The next part of the solution is the invoker, which is stored in the Editor.Editor unit. It is defined as a simple class that can execute and undo commands, as shown here:
type TEditor = class strict private FUndo: TStack<TCommand>; public constructor Create; destructor Destroy; override; procedure Execute(command: TCommand); procedure Undo(command: TCommand); function IsUndoEmpty: boolean; function PopLastCommand: TCommand; end;
Leaving the boring creation and destruction aside (for more details, see the source code), the interesting methods are implemented as follows:
procedure TEditor.Execute(command: TCommand);begin command.Execute; FUndo.Push(command);end;function TEditor.IsUndoEmpty: boolean;begin Result := FUndo.Count = 0; ...
Read now
Unlock full access