const
EM_GETSCROLLPOS = WM_USER + 221;
EM_SETSCROLLPOS = WM_USER + 222;
procedure TForm4.Button1Click(Sender: TObject);
var
p1, p2 : TPoint;
begin
RichEdit1.SetFocus;
SendMessage (Richedit1.Handle, EM_GETSCROLLPOS, 0, LParam (@p1));
RichEdit1.SelStart := FSelStart;
RichEdit1.SelLength := FSelLength;
SendMessage (Richedit1.Handle, EM_GETSCROLLPOS, 0, LParam (@p2));
if p1.Y - p2.Y < 0
then
Inc (p2.Y, Richedit1.height
div 2)
else
Dec (p2.Y, Richedit1.height
div 2);
SendMessage (Richedit1.Handle, EM_SETSCROLLPOS, 0, LParam (@p2))
end;
procedure TForm4.RichEdit1Exit(Sender: TObject);
begin
FSelStart := RichEdit1.SelStart;
FSelLength := RichEdit1.SelLength
end;