Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to replace WM_HSCROLL handler for TRxRichEdit?

Posted on 2000-03-20
6
Medium Priority
?
495 Views
Last Modified: 2012-05-04
Hi,

My problem is as follows:
I have 2 TRxRichEdit controls on my form and I need to link them so that if user scrolls contents of one of them (using scrollbar) horizintally then contents of another TRxRichEdit gets scrolled too.

May be someone have some sample code which solves this or similar problem?..

Thanks in advance, amv.
0
Comment
Question by:amv
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2637902
hi,
this is example syncronizing component for  memos ,it should be same for richedit also just need to change the instances of memo to richedit the install and use a ne richedit.:

unit SyncMemo;
 
interface
 
uses
  Windows, Messages, Classes, SysUtils, Graphics, Controls, Forms, Dialogs,   StdCtrls;
 
const
  {User messages to use if buddy is TSyncMemo }
  UM_BUDDYHSCROLL = WM_USER + 1111;
  UM_BUDDYVSCROLL = WM_USER + 1112;
type
 
  TSyncMemo = class(TMemo)
  private
    { Private declarations }
    { Handlers for windows messages }
    procedure WMVScroll( Var msg: TMessage );
      message WM_VSCROLL;
    procedure WMHScroll( Var msg: TMessage );
      message WM_HSCROLL;
    procedure UMBuddyHScroll( Var msg: TMessage );
      message UM_BUDDYHSCROLL;
    procedure UMBuddyVScroll( Var msg: TMessage );
      message UM_BUDDYVSCROLL;
 
    Procedure SetScrollControl( aScrollControl: TCustomMemo );
  protected
    { Protected declarations }
    FInBuddyScroll: Boolean;
    FBuddy: TCustomMemo;
    FSyncStyle: TScrollStyle;
  public
    { Public declarations }
  published
    { Published declarations }
 
    property SyncStyle: TScrollStyle read FSyncStyle write FSyncStyle;     property ScrollControl: TCustomMemo read FBuddy write SetScrollControl;   end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('Test', [TSyncMemo]);
end;
 
{ TSyncMemo }
 
procedure TSyncMemo.UMBuddyHScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_HSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncMemo.UMBuddyVScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_VSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncMemo.WMHScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssHorizontal]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TsyncMemo Then
      FBuddy.Perform( UM_BUDDYHSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_HSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;
 
procedure TSyncMemo.WMVScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssVertical]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TsyncMemo Then
      FBuddy.Perform( UM_BUDDYVSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_VSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;
 
Procedure TSyncMemo.SetScrollControl( aScrollControl: TCustomMemo ); Begin
  If (aScrollControl <> FBuddy) and (aScrollControl <> Self) Then     FBuddy := aScrollControl;
End;
 
end.

Hope it helps

Regards Barry
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2637913
This one also by Inthe
..
..
var
Oldpos :Integer;

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode:
                                          TScrollCode;
var ScrollPos: Integer);
begin

      if scrollpos > oldpos then begin
         sendmessage(memo1.handle,wm_vscroll,sb_linedown,scrollpos);
         sendmessage(memo2.handle,wm_vscroll,sb_linedown,scrollpos);
      end
      else if  scrollpos < oldpos then begin
         sendmessage(memo1.handle,wm_vscroll,sb_lineup,scrollpos);
         sendmessage(memo2.handle,wm_vscroll,sb_lineup,scrollpos);
      end;
      oldpos := scrollpos;
end;

or from: AttarSoftware
unit Unit1;

interface
uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
                        StdCtrls;

 type
                        TForm1 = class(TForm)
                          ScrollBox1: TScrollBox;
                          Label1: TLabel;
                          ScrollBox2: TScrollBox;
                          Label2: TLabel;
                          procedure FormShow(Sender: TObject);
                        private
                          { Private declarations }
                          oldWndMethod : tWndMethod ;
                          procedure MyWndProc( var msg : tMessage ) ;
                        public
                          { Public declarations }
                        end;

                      var
                        Form1: TForm1;

                      implementation

                      {$R *.DFM}

procedure tForm1.MyWndProc( var msg : tMessage ) ;
begin
       if( msg.Msg = WM_VSCROLL ) then
                          PostMessage( ScrollBox2.Handle, WM_VSCROLL,                           msg.WParam, msg.LParam ) ;
                        oldWndMethod( msg ) ;
end ;

procedure TForm1.FormShow(Sender: TObject);
begin
              oldWndMethod := ScrollBox1.WindowProc ;
              ScrollBox1.WindowProc := MyWndProc ;
end;

end.

                      -------------------------------------
Indi
0
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 2637976
this one is best yet ,it is desendant of rxrichedit so can just install and drop 2 on form and set the 2 new propertys
ScrollControl and SyncStyle

as in example at bottom:


unit SyncronizedRxRichEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, RxRichEd;

const
  UM_BUDDYHSCROLL = WM_USER + 1111;
  UM_BUDDYVSCROLL = WM_USER + 1112;

type
  TSyncronizedRxRichEdit = class(TRxRichEdit)
  private
    { Private declarations }
   procedure WMVScroll( Var msg: TMessage );
     message WM_VSCROLL;
   procedure WMHScroll( Var msg: TMessage );
     message WM_HSCROLL;
   procedure UMBuddyHScroll( Var msg: TMessage );
     message UM_BUDDYHSCROLL;
   procedure UMBuddyVScroll( Var msg: TMessage );
     message UM_BUDDYVSCROLL;
   Procedure SetScrollControl( aScrollControl: TSyncronizedRxRichEdit );
  protected
    { Protected declarations }
    FInBuddyScroll: Boolean;
    FBuddy: TSyncronizedRxRichEdit;
    FSyncStyle: TScrollStyle;
  public
    { Public declarations }
  published
    { Published declarations }
  property SyncStyle: TScrollStyle read FSyncStyle write FSyncStyle;
  property ScrollControl: TSyncronizedRxRichEdit read FBuddy write SetScrollControl;
    end;

procedure Register;

implementation

procedure TSyncronizedRxRichEdit.UMBuddyHScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_HSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncronizedRxRichEdit.UMBuddyVScroll(var msg: TMessage);
begin
  FInBuddyScroll:= True;
  try
    msg.result := Perform( WM_VSCROLL, msg.wparam, msg.lparam );   finally
    FInBuddyScroll := False;
  end;
end;
 
procedure TSyncronizedRxRichEdit.WMHScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssHorizontal]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TSyncronizedRxRichEdit Then
      FBuddy.Perform( UM_BUDDYHSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_HSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;

procedure TSyncronizedRxRichEdit.WMVScroll(var msg: TMessage);
begin
  If not FInBuddyScroll and
    (FSyncStyle In [ssBoth, ssVertical]) and
    Assigned( FBuddy )
  Then Begin
    If FBuddy Is TSyncronizedRxRichEdit Then
      FBuddy.Perform( UM_BUDDYVSCROLL, msg.wparam, msg.lparam )
    Else
      FBuddy.Perform( WM_VSCROLL, msg.wparam, msg.lparam );
  End;
  inherited;
end;

Procedure TSyncronizedRxRichEdit.SetScrollControl( aScrollControl: TSyncronizedRxRichEdit ); Begin
  If (aScrollControl <> FBuddy) and (aScrollControl <> Self) Then     FBuddy := aScrollControl;
End;

procedure Register;
begin
  RegisterComponents('Inthe.Future', [TSyncronizedRxRichEdit]);
end;

end.





example of use :
drop 2 on a form and a button and:

procedure TForm1.FormCreate(Sender: TObject);
begin
SyncronizedRxRichEdit1.SyncStyle := ssBoth;
SyncronizedRxRichEdit1.ScrollControl := SyncronizedRxRichEdit2;
SyncronizedRxRichEdit2.SyncStyle := ssBoth;
SyncronizedRxRichEdit2.ScrollControl := SyncronizedRxRichEdit1;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
SyncronizedRxRichEdit1.Lines.loadfromfile('c:\autoexec.bat');
SyncronizedRxRichEdit2.lines.loadfromfile('c:\autoexec.bat');
end;


ps
Hi Indi ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:amv
ID: 2640694
Great thanks guys!! I got it worked with your help!!
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2642287
great
In the end you allways beat yourself, barry
cheers
Indi
0
 
LVL 17

Expert Comment

by:inthe
ID: 2642341
hey im no "sado masacist"  <-- sp  ;-))
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question