//************************* Source for the TMyRichEdit component...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TMyRichEdit =
class(TRichEdit)
protected
procedure OnWMHScroll(
var Message : TMessage);
message WM_HSCROLL;
procedure OnWMVScroll(
var Message : TMessage);
message WM_VSCROLL;
procedure CNNotify(
var Message: TWMNotify);
message CN_NOTIFY;
public
SyncWithRichEdit : TRichEdit;
end;
procedure Register;
implementation
uses
RichEdit;
{ TMyRichEdit }
procedure TMyRichEdit.OnWMHScroll(
var Message: TMessage);
begin
SendMessage(SyncWithRichEdit.Handle, WM_HSCROLL,
Message.WParam,
Message.LParam);
end;
procedure TMyRichEdit.OnWMVScroll(
var Message: TMessage);
begin
SendMessage(SyncWithRichEdit.Handle, WM_VSCROLL,
Message.WParam,
Message.LParam);
inherited;
end;
procedure TMyRichEdit.CNNotify(
var Message: TWMNotify);
var
Diff : Integer;
c : integer;
begin
Inherited;
with Message do
case NMHdr^.code
of
EN_SELCHANGE:
begin
Diff := SyncWithRichEdit.Perform(EM_GETFIRSTVISIBLELINE, 0, 0) -
Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
c := abs(diff);
while c > 0
do
begin
if diff < 0
then
SyncWithRichEdit.perform(em_scroll, SB_LINEDOWN, 0)
else
SyncWithRichEdit.perform(em_scroll, SB_LINEUP, 0);
dec(c);
end;
end;
end;
end;
procedure Register;
begin
RegisterComponents('
Samples', [TMyRichEdit]);
end;
end.
//************************* Form to test it with - just put a TRichEdit and a TMyRichEdit on it
unit RicheditForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, Unit1;
type
TForm1 =
class(TForm)
RichEdit1: TRichEdit;
MyRichEdit1: TMyRichEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyRichEdit1.SyncWithRichEdit := RichEdit1;
end;