Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I save and restore the current scroll position in a TRichEdit component?

0
Posted

How do I save and restore the current scroll position in a TRichEdit component?

0

First, a brief description of the problem: Assume that you are writing a chat room program. As new messages are a posted in the chat room, you want to append them to the text in the control. However, to do this, you must position the caret at the bottom of the text and then insert the text. Finally, you need to restore the original caret position (easy) and scroll back such that the top line displayed is the same one as before inserting the text (not so easy). Here is a trick posted by Peter Below (TeamB) in a Delphi forum. I have translated, modified, and expanded the original post somewhat for presentation here. Hopefully, I have not munged it too badly.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.