Solved

Synchronising scrolling

Posted on 2000-03-06
13
245 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

758 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

18 Experts available now in Live!

Get 1:1 Help Now