• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Synchronising scrolling

How can I synchronise horizontal scrolling between three components, all of type: TScrollingWinControl.

I have a scroll bar visible on the first component. (I have hidden the scrollbars on the other two components).

How can I get the other two components to scroll when I move the scrollbar of the first components?

0
zebada
Asked:
zebada
  • 5
  • 3
  • 2
  • +3
1 Solution
 
hyperengCommented:
In the onScroll event you just use

ScrollBar2.Postition := ScrollPos;
ScrollBar3.Position := ScrollPos;

Regards Lars
0
 
doncovCommented:
I shall add:
In TScrollingWinControl event onScroll not(Delphi5). If into any other event ScrollBox1 to insert something:

ScrollBox2.VertScrollBar.Position := ScrollBox2.VertScrollBar.Position+10

then It turns out scrolling.
0
 
zebadaAuthor Commented:
Lars,
I hate to appear stupid (sometimes I just can't help it) but where is the OnScroll event for a TSCrollingWinControl and how do I put code in it?


Doncov,
I don't understand what you mean by:
"In TScrollingWinControl event onScroll not(Delphi5). If into any other event ScrollBox1 to insert something:"

Cheers
Paul


0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
AttarSoftwareCommented:
If you override the WindowProc procedure on your main scrolling window with your own own one (make sure it sends all messages to the WndProc at the end), and then you can catch the message that the window is scrolling and PostMessage it to the handles of all your other scrolling windows...

I cannot remember the message name off hand, but this should work...

Remember :

(in FormCreate)

  ScrollingWindow1.WindowProc := MyWindowProc ;

and at the end of MyWindowProc:

  ScrollingWindow1.WndProc( <parameters> ) ;

Srry for being so vague, but I cannot remeber the parameters, and my Delphi machine is at the menders...

Good luck,

Tim.
0
 
AttarSoftwareCommented:
I think the message is:

SBM_SETPOS

not 100% sure though ;O)

Tim.
0
 
ptmcompCommented:
The message is WM_VSCROLL, but it's send to the scrollbox and not to the form. >:0{
0
 
IndefreiCommented:
Saw this for to memos once,
perhaps you can use it for your components

var
     Form1: TForm1;
     oldpos : integer; {hold old position to determine if scrolling up or
                    down}

implementation

                    {$R *.DFM}

                    procedure TForm1.Button2Click(Sender: TObject);
                    begin
                    memo1.lines.loadfromfile('c:\autoexec.bat');
                    memo2.lines.loadfromfile('c:\autoexec.bat');

                    end;

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;

cheers
Indi
0
 
AttarSoftwareCommented:
Right, maybe I didn't make myself clear...

This should clear it up:

--------------------------------------

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.

-------------------------------------

Works for me, anyways...

Good luck again :O)

Tim.
0
 
IndefreiCommented:
anybody at home ?
0
 
AttarSoftwareCommented:
Did that work or not? :OI

Tim.
0
 
IndefreiCommented:
Hi, Tim
good luck for your first T-Shirt
Cheers
Indi
0
 
zebadaAuthor Commented:
Sorry for not responding sooner, I've got a million other things to do.
I appreciate the responses, thanks.
I haven't had time to implement any of them.

I have actually "solved" the problem temporarily by just setting the scrollbar position of the other components from within the Paint method of the first component. (but only if the scroll positions are different).

Is there any problems that I might run into by doing this?

Tim, I will probably implement your solution when I get time. If you'll be so kind as to answer any implementation questions when the time comes.

Thanks
Paul

0
 
AttarSoftwareCommented:
Yeah, no worries ;O)

Hurrah, my first T-Shirt :O) :O)

Just in time for summer too :O)

Tim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now