unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyListBox =
class(TListBox)
private
FRef : TCustomListBox;
procedure WMHScroll(
var Message: TWMHScroll);
message WM_HSCROLL;
procedure WMVScroll(
var Message: TWMVScroll);
message WM_VSCROLL;
public
constructor Create(AOwner: TComponent);
override;
published
property Reference : TCustomListBox
read FRef
write FRef;
end;
TForm1 =
class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
LBox : TMyListBox;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var a:integer;
begin
Randomize;
LBox := TMyListBox.Create(self);
with LBox
do
begin
Parent := Self;
Visible := true;
Top := 10;
Left := 10;
Width := 200;
Height := 200;
Reference := listbox1;
end;
for a:=0
to 100
do
begin
ListBox1.Items.Add(IntToStr(Random(100000)));
LBox.Items.Add(IntToStr(Random(100000)));
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
LBox.Free;
end;
{ TMyListBox }
constructor TMyListBox.Create(AOwner: TComponent);
begin
inherited;
FRef :=
nil;
end;
procedure TMyListBox.WMHScroll(
var Message: TWMHScroll);
begin
inherited;
end;
procedure TMyListBox.WMVScroll(
var Message: TWMVScroll);
begin
inherited;
if Assigned(FRef)
then FRef.TopIndex := TopIndex;
end;