Solved

How to replace WM_HSCROLL handler for TRxRichEdit?

Posted on 2000-03-20
6
468 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 210
Delphi XE10, MySQL Query 4 126
Intraweb download file link ? 1 107
LAN or WAN ? 11 81
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now