Scroll Memo together

Hi Guy's

I have 2 memo boxes side by side,
I want to have a vertical scroll bar on the right Memo Box but no scroll bar on the left memo box.

How can I make them scroll together by scrolling on the 1 vertical scroll bar on the right memo box.

Thanks
Asw
LVL 1
AswAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
you could try like this using a Tscrollbar and set kind = sbvertical and place beside memo2 giving the appearance it is the memos scrollbar,then some code like:

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;


cant see any other way to get it to work,
Regards Barry
0
edeyCommented:
can also use the scrollby method instead of sending messages (prob just a wrapper though :)


GL
Mike
0
intheCommented:
hi mike
i tried using scrollby() first but the memo's painting was going a bit strange..
i called it like:
memos.scrollby(0,scrollpos);
is that normal?
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

edeyCommented:
Hmmm...

Might want to check the scrollpos is not the position you want to scroll too, but rather the pixels you need to scroll inorder to get there


GL
Mike
0
kretzschmarCommented:
hi all,

a other way

unit mem_scroll_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Memo1: TMemo;
    ScrollBar1: TScrollBar;
    Memo2: TMemo;
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Opendialog1.Execute then
  begin
    Memo1.Lines.LoadFromFile(Opendialog1.FileName); //Load first file
    if Opendialog1.Execute then
      Memo2.Lines.LoadFromFile(Opendialog1.FileName);  //load second
    If Memo1.Lines.Count >= Memo2.Lines.Count then  //adjust scrollbar max
      ScrollBar1.Max := Memo1.Lines.Count
    else
      ScrollBar1.Max := Memo2.Lines.Count;
  end;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  Memo1.Lines.BeginUpdate;  //avoid a bit flicker
  Memo2.Lines.BeginUpdate;
  Memo1.Perform(EM_LineScroll,0,-ScrollBar1.Max); //back to top
  Memo1.Perform(EM_LineScroll,0,ScrollBar1.Position); //scroll to pos
  Memo2.Perform(EM_LineScroll,0,-ScrollBar1.Max);
  Memo2.Perform(EM_LineScroll,0,ScrollBar1.Position);
  Memo1.Lines.EndUpdate;
  Memo2.Lines.EndUpdate;
end;

end.

remark, instead of back to top you can also do a relativ step like

procedure TForm1.ScrollBar1Change(Sender: TObject);
var CurrentTopLine : Integer;
begin
  Memo1.Lines.BeginUpdate;  //avoid a bit flicker
  Memo2.Lines.BeginUpdate;
  CurrentTopLine := Memo1.Perform(EM_GetFirstVisibleLine,0,0);  //get currentTopLine
  Memo1.Perform(EM_LineScroll,0,ScrollBar1.Position-CurrentTopLine); //scroll to pos
  Memo2.Perform(EM_LineScroll,0,ScrollBar1.Position-CurrentTopLine);
  Memo1.Lines.EndUpdate;
  Memo2.Lines.EndUpdate;
end;

have fun

meikl ;-)
0
AswAuthor Commented:
Hi Guy's ,

Thanks for all your help.

I need to give the points to Inthe, because I used his comment.

Inthe please give me an answer so I can give the points.

Thanks Kretzschmar, edey
Asw
0
intheCommented:
cool :-))
have merry XMas & happy new year
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.