[Lazarus] how to set two memos for parallel text editing ?
Howard Page-Clark
hdpc at talktalk.net
Wed May 28 11:15:49 CEST 2014
On 28/05/2014 00:46, Etienne Leblois wrote:
> how to manage that scrolling or arrowing up in one memo will also
> scroll up the other one ?
The following Windows example shows how to synchronise scrolling between
two memos (Memo1, Memo2) using scrollbar movement. Responding to memo
caret movement in addition would require more code based on the same
message-interception ideas.
//== code ==
unit mainScrollMemo;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, Controls, LMessages, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
procedure FormCreate(Sender: TObject);
private
FOrgMemoWndProc: TWndMethod;
procedure MemoWndMethod(var theMessage: TLMessage);
end;
var
Form1: TForm1;
implementation
uses windows;
{$R *.lfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FOrgMemoWndProc:=Memo1.WindowProc;
Memo1.WindowProc:=@MemoWndMethod;
memo1.Lines.LoadFromFile('..\..\mainscrollmemo.pp');
memo2.Lines.LoadFromFile('..\..\mainscrollmemo.pp');
end;
procedure TForm1.MemoWndMethod(var theMessage: TLMessage);
begin
FOrgMemoWndProc(theMessage);
if theMessage.msg=LM_VSCROLL then
SendMessage(Memo2.Handle, WM_VSCROLL, theMessage.wParam ,
theMessage.lParam);
if theMessage.wParamlo=SB_THUMBTRACK then
SetScrollPos(Memo2.Handle, SB_VERT, theMessage.wParamhi, True);
end;
end.
//== code end ==
You should be able to adapt this to your needs.
Howard
More information about the Lazarus
mailing list