Synchronize scrolling for two components lazarus / 62-General ---------------------------------------------------------------------- wcage03 · 2018-11-07 23:44 I am trying to have multiple TDBGrid components on a page and have them all scroll horizontally in sync (i.e. if the horizontal scroll bar is moved left or right on any one of the components, all will move accordingly).  I have searched for a couple of days on this and I can find the topic in numerous places for other components (mainly TMemo), but I unable to get the examples to work. Conceptually, I need to be notified that a component is scrolling; capture the scroll position and push that out to the others.  I am not making progress.  I have one example that I found that I have focused on, without luck.  Again, it is for a TMemo, but I figure once I get a solution I can fit it into another component (or at least know that it won't work, if that is the case).  I have attached the code that I found in my search that seemed most straightforward.  When I compile, I get an error in the overridden create method where the handler is being replaced. If anyone could point me in the right direction with this sample code or toward something more appropriate i would appreciate it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, msghandler,  LCLType, LCLIntf, Buttons, Messages; type   TMemo=class(StdCtrls.TMemo) // Just to add things to TMemo class only for this unit  private     BusyUpdating:Boolean; // To avoid circular stack overflow     SyncMemo:TMemo; // To remember the TMemo to be sync     Old_WindowProc:TWndMethod; // To remember old handler     procedure New_WindowProc(var Mensaje:TMessage); // The new handler  public     constructor Create(AOwner:TComponent);override; // The new constructor     destructor Destroy;override; // The new destructor  end;   { TForm1 }   TForm1 = class(TForm)    Memo1: TMemo;    Memo2: TMemo;    procedure FormCreate(Sender: TObject);  private    procedure pnlMemo2Resize(Sender: TObject);  public   end; var  Form1: TForm1; implementation {$R *.lfm}procedure TMemo.New_WindowProc(var Mensaje:TMessage);begin     Old_WindowProc(Mensaje); // Call the real handle before doing anything     if  (WM_PAINT<>Mensaje.Msg) // If not when need to be repainted to improve speed       or         BusyUpdating // To avoid circular stack overflow       or         (not Assigned(SyncMemo)) // If not yet set (see TForm1.FormCreate bwlow)     then Exit; // Do no more and exit the procedure     BusyUpdating:=True; // Set that object is busy in our special action     SyncMemo.Perform(WM_HSCROLL,SB_THUMBPOSITION+65536*GetScrollPos(Han dle,SB_HORZ),0); // Send to the other TMemo a message to set its horizontal scroll as it is on this TMemo     BusyUpdating:=False; // Set that the object is no more busy in our special actionend; constructor TMemo.Create(AOwner:TComponent); // The new constructorbegin     inherited Create(AOwner); // Call real constructor     BusyUpdating:=False; // Initialize as not being in use, to let enter     Old_WindowProc:=WindowProc; // Remember old handler     WindowProc:=New_WindowProc; // Replace handler with new oneend; destructor TMemo.Destroy; // The new destructorbegin     WindowProc:=Old_WindowProc; // Restore the original handler     inherited Destroy; // Call the real destructorend; procedure TForm1.FormCreate(Sender: TObject);begin     Memo1.SyncMemo:=Memo2; // Tell Memo1 what TMemo must sync (Memo2)     Memo2.SyncMemo:=Memo1; // Tell Memo2 what TMemo must sync (Memo1)end; procedure TForm1.pnlMemo2Resize(Sender: TObject);begin     //Memo2.Height:=pnlMemo2.Height+20; // Make height enough big to cause horizontal scroll bar be out of TPanel visible area, so it will not be seen by the userend; end.