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

x
?
Solved

Synchronising scrolling

Posted on 2000-03-06
13
Medium Priority
?
256 Views
Last Modified: 2010-04-04
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
Comment
Question by:zebada
  • 5
  • 3
  • 2
  • +3
13 Comments
 

Expert Comment

by:hypereng
ID: 2590630
In the onScroll event you just use

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

Regards Lars
0
 

Expert Comment

by:doncov
ID: 2590922
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
 
LVL 6

Author Comment

by:zebada
ID: 2591002
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
Technology Partners: 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!

 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2591147
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
 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2591698
I think the message is:

SBM_SETPOS

not 100% sure though ;O)

Tim.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2593094
The message is WM_VSCROLL, but it's send to the scrollbox and not to the form. >:0{
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2593512
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
 
LVL 1

Accepted Solution

by:
AttarSoftware earned 400 total points
ID: 2596688
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
 
LVL 1

Expert Comment

by:Indefrei
ID: 2598140
anybody at home ?
0
 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2604717
Did that work or not? :OI

Tim.
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2606124
Hi, Tim
good luck for your first T-Shirt
Cheers
Indi
0
 
LVL 6

Author Comment

by:zebada
ID: 2611880
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
 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2611894
Yeah, no worries ;O)

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

Just in time for summer too :O)

Tim.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 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