I would like to send a BackSpace control char to a TMemo like the user would actually press the BackSpace button.
My Memo is readonly and if I click a button it should delete the last char in the memo.
I would like to do that without using Memo.Text := … (so no redraw or beginupdate, etc.)
Is that possible, if yes, how?
Thank you for your help.
EDIT: I tried to add #8 but no luck…
Sending a key press to a read only memo won’t work. The key press will be ignored because the memo is read only. To delete the final character of a memo in an efficient way, that is without replacing the entire contents, you can use
EM_SETSELandEM_REPLACESEL.Or if you prefer a pure VCL version which wraps up these Windows messages:
The latter probably sends a few more Windows messages, but is much easier to read. I would prefer the latter option.
One possible problem I can see with this is that it may not do what you want with line breaks. Since a Windows line break is two characters (CR+LF), you would need to delete two characters if the last character in the memo was LF. To handle that you can probably do it like this: