whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

83 Visitors Online


 
...synchronize the Scrolling of two TStringgrids?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (26):  
     


{1.}

unit SyncStringGrid;

interface

uses
  
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  
TSyncKind = (skBoth, skVScroll, skHScroll);
  TSyncStringGrid = class(TStringGrid)
  private
    
FInSync: Boolean;
    FsyncGrid: TSyncStringGrid;
    FSyncKind: TSyncKind;
    { Private declarations }
    
procedure WMVScroll(var Msg: TMessage); message WM_VSCROLL;
    procedure WMHScroll(var Msg: TMessage); message WM_HSCROLL;
  protected
    
{ Protected declarations }
  
public
    
{ Public declarations }
    
procedure DoSync(Msg, wParam: Integer; lParam: Longint); virtual;
  published
    
{ Published declarations }
    
property SyncGrid: TSyncStringGrid read FSyncGrid write FSyncGrid;
    property SyncKind: TSyncKind read FSyncKind write FSyncKind default skBoth;
  end;

procedure Register;

implementation

procedure Register
;
begin
  
RegisterComponents('Samples', [TSyncStringGrid]);
end;

procedure TSyncStringGrid.WMVScroll(var Msg: TMessage);
begin
  if not 
FInSync and
    
Assigned(FSyncGrid) and
    
(FSyncKind in [skBoth, skVScroll]) then
    
FSyncGrid.DoSync(WM_VSCROLL, Msg.wParam, Msg.lParam);
  inherited;
end;

procedure TSyncStringGrid.WMHScroll(var Msg: TMessage);
begin
  if not 
FInSync and
    
Assigned(FSyncGrid) and
    
(FSyncKind in [skBoth, skHScroll]) then
    
FSyncGrid.DoSync(WM_HSCROLL, Msg.wParam, Msg.lParam);
  inherited;
end;

procedure TSyncStringGrid.DoSync(Msg, wParam: Integer; lParam: Longint);
begin
  
FInSync := True;
  Perform(Msg, wParam, lParam);
  FinSync := False;
end;

end.

{****************************************}
{2.}

private
   
OldGridProc1, OldGridProc2: TWndMethod;
   procedure Grid1WindowProc(var Message: TMessage);
   procedure Grid2WindowProc(var Message: TMessage);
 public

{...}

procedure TForm1.Grid1WindowProc(var Message: TMessage);
begin
  
OldGridProc1(Message);
  if ((Message.Msg = WM_VSCROLL) or (Message.Msg = WM_HSCROLL) or
      Message
.msg = WM_Mousewheel)) then
  begin
    
OldGridProc2(Message);
  end;
end;

procedure TForm1.Grid2WindowProc(var Message: TMessage);
begin
  
OldGridProc2(Message);
  if ((Message.Msg = WM_VSCROLL) or (Message.Msg = WM_HSCROLL) or
     
(Message.msg = WM_Mousewheel)) then
  begin
    
OldGridProc1(Message);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
OldGridProc1 := StringGrid1.WindowProc;
  OldGridProc2 := StringGrid2.WindowProc;
  StringGrid1.WindowProc := Grid1WindowProc;
  StringGrid2.WindowProc := Grid2WindowProc;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners