Solved

How to replace WM_HSCROLL handler for TRxRichEdit?

Posted on 2000-03-20
6
472 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 100 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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