Solved

Synchronising scrolling

Posted on 2000-03-06
13
249 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
Industry Leaders: 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tidtcpserver connection lost handle 2 109
Delphi inherited method 6 78
How to make Sign in, using Clientdataset? 1 33
Get weeknumber and year from date 4 25
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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