Adding to Advmemo Undolist

I have a function that adds "" to the beginning of selected lines. Because I am manipulating the memo contents programmatically, the undolist does not have entries for the changes. I have spent a fair amount of time looking at the the various TUndo descendents but can't figure out out to add the changes to the undo list. Can you point me in the right direction? The code for the function is below:

procedure TEditForm.CommentExecute(Sender: TObject);
  I, Temp, SelStart, SelEnd: Integer;
  SelStart := Memo1.SelStartY;
  SelEnd := Memo1.SelEndY;
  if SelStart > SelEnd then
    Temp := SelEnd;
    SelEnd := SelStart;
    SelStart := Temp;
  for I := SelStart to SelEnd do
    Memo1.Lines := '' + Memo1.Lines;

Also, I have some functions that use the Memo.Lines.Insert() to replace selected text. Could you also point me in the right direction on adding changes made in that manner to the undolist?

Thank you very much!

Directly manipulating AdvMemo.Lines is indeed not tracked by the undo buffer (by design).
To insert text tracked by the undo buffer, please use AdvMemo.InsertText()


I am using version the current version of TScrMemo and it is not tracking using:
scrMemo.InsertText('some text');

Can you advise?


I retested this here but I cannot see an issue.


procedure TForm1.Button1Click(Sender: TObject);

procedure TForm1.Button2Click(Sender: TObject);

Click on button 1 to insert text and then button 2 will undo this insert.

Thanks for the reply.

And you tested with TScrMemo?
Did your test insert into text or a blank memo?

I will make a test project if needed.

I tested both inserting text in a blank memo and in a memo that contains text.


I'm not sure what you mean by this? The test was described by Bruno in the post above, in Button1Click and Button2Click events.

If you read his response you see he replied “I tested both inserting text in a blank memo and in a memo that contains text.

I will send a test project soon.

To close out my part at this point, I sent an example in, the issue has been resolved and the fix will be in the next release.

Thanks Bruno

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