Solved

How to replace WM_HSCROLL handler for TRxRichEdit?

Posted on 2000-03-20
6
462 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

19 Experts available now in Live!

Get 1:1 Help Now