Working in C++ Builder 10 Seattle on Win7-64.
I have a TRichEdit control into which I can write from a button click event:
MyRichEdit->SelText = t_string;
I want to be able to undo that change, so I have a menu item with shortcut Ctrl+Z that does this:
SendMessage(MyRichEdit->Handle, EM_UNDO, 0, 0);
The Undo works as expected if I have typed into the rich edit, but not to undo the programmatically assigned "paste".
I had similar code in an old application that was built with Borland C++ Builder v6, and it works there.
My question then is: Should the above code undo the write-to-SelText? Or is there something else I need to do?
The implementation of the
SelTextsetter looks like this:The documentation for
EM_REPLACESELsays:The VCL is sending
0which isFALSEand so the operation cannot be undone. You will need to avoid usingSelTextand instead send theEM_REPLACESELdirectly, passingTRUEaswParam.I examined the source code for the Delphi 6 VCL and it too always passes
0forwParamwhen sending this message, so I would have expected the old versions of the VCL to behave in the same way. All the same, you now know how to resolve the issue.As an aside, you can replace sending of
EM_UNDOwith a call toMyRichEdit->Undo()which does exactly the same thing.