La solución de roman, con una pequeña modificación, para que también funcione al arrastrar el botón central de la barra de desplazamiento:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
private
Scrolling: Boolean;
MemoOldWndProc: TWndMethod;
RichEditOldWndProc: TWndMethod;
procedure MemoWndProc(Var Msg: TMessage);
procedure RichEditWndProc(Var Msg: TMessage);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Scrolling := false;
MemoOldWndProc := Memo1.WindowProc;
RichEditOldWndProc := RichEdit1.WindowProc;
Memo1.WindowProc := MemoWndProc;
RichEdit1.WindowProc := RichEditWndProc;
end;
procedure TForm1.MemoWndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_VSCROLL) and not Scrolling then
begin
Scrolling := true;
if Msg.WParam < 9 then
RichEdit1.Perform(WM_VSCROLL, Msg.WParam, Msg.LParam)
else
RichEdit1.Perform(WM_VSCROLL, (Msg.WParam-5)*13+5, Msg.LParam);
Scrolling := false;
end;
MemoOldWndProc(Msg);
end;
procedure TForm1.RichEditWndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_VSCROLL) and not Scrolling then
begin
Scrolling := true;
if Msg.WParam < 9 then
Memo1.Perform(WM_VSCROLL, Msg.WParam, Msg.LParam)
else
Memo1.Perform(WM_VSCROLL, Round((Msg.WParam-5)/13/65536)*65536+5, Msg.LParam);
Scrolling := false;
end;
RichEditOldWndProc(Msg);
end;
end.