TStringsMove (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a list box and a button on a form. The list box contains items when the form appears. When you click the button, the selected item in the list box is moved to the top of the list box.

Code

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (ListBox1.ItemIndex in [0..9]) then
    ListBox1.Items.Move(ListBox1.ItemIndex, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  ListBox1.MultiSelect := False;
  Button1.Caption := 'Move to Top';
  for I := 1 to 10 do
    ListBox1.Items.Add('Item ' + IntToStr(I));
end;

Uses