Undo for objects created programmatically

Hi, I see a strange diagram reaction to the undo action. I create block programmatically (TDiagramBlock.Create) and then remove it to new position, just using the mouse cursor on the screen. If I then click undo action, the block becomes invisible (or deleted?), but logically, it should have just returned to its start position. If I create block using standard DiagramButtons container — all works fine.

What am I doing wrong? I am attaching the test, but I think that the question is already clear.

undo_example.zip (53.9 KB)

By the way, the FDiagram.ClearUndoStack method helped if I call it after creating the block. If this is the correct solution, perhaps it needs to be added to the help documentation, in the "Working with diagram programatically" section?

You should always call PushUndoStack to "save a snapshot" that you want to revert to when you can undo:

procedure TForm1.Button1Click(Sender: TObject);
  Block: TDiagramBlock;
  Block := TDiagramBlock.Create(Self);
  Block.Diagram := Diagram1;
  Block.Color := clWhite;
  Diagram1.PushUndoStack('block create');
1 Like

Thanks a lot, Wagner!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.