Solved

Synchronising scrolling

Posted on 2000-03-06
13
246 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
 
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
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.

 
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 100 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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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