那你就继承一下,写个类好了.例如处理VScroll时的过程为procedure MyScroll1;
就设
SrlStringGrid1.OnVScrollHandle := MyScroll1;
SrlStringGrid2.OnVScrollHandle := MyScroll1;
SrlStringGrid3.OnVScrollHandle := MyScroll1;
下面的代码如果你有空,可以完善一下.
==========================================================
unit SrlStringGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, StdCtrls;
type
TVscrollHandle = procedure of object;
TSrlStringGrid = Class(TStringGrid)
private
FOldWndProc : TWndMethod;
FHandleVScroll : TVscrollHandle;
procedure MyWndProc(var Message: TMessage);
public
Constructor Create(AOwner : TComponent);override;
property OnVScrollHandle : TVScrollHandle read FHandleVScroll write FHandleVScroll;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TSrlStringGrid]);
end;
{ TSrlStringGrid }
constructor TSrlStringGrid.Create(AOwner: TComponent);
begin
inherited;
FOldWndProc := WindowProc;
WindowProc := MyWndProc;
end;
procedure TSrlStringGrid.MyWndProc(var Message: TMessage);
begin
if Message.Msg = WM_VSCROLL then FHandleVScroll;
FOldWndProc(Message);
end;
end.