unit TopIndex;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Edit1: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: TopIndex
// Property: StdCtrls.TCustomListBox.TopIndex

// BeginCode
{
The following example uses a list box containing a list of
strings, a button, and an edit box on a form. When the user
runs the application and clicks the button, the third item
in the list becomes the first item, and the index value of
that item appears in the edit box. The index value displayed
is 2, indicating the third item in the list (the first item
in the list has an index value of 0):
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.TopIndex := 2;
  Edit1.Text := IntToStr(ListBox1.TopIndex);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Number: Integer;
begin
  for Number := 1 to 20 do
    ListBox1.Items.Add('Item ' + IntToStr(Number));
end;
// EndCode
// EndExample: TopIndex
end.
