ListIndex(ListBoxなど)
ListIndexプロパティは ListBoxコントロールなどの現在選択されているインデックスを返します。Delphiでは, 「ItemIndex」プロパティで取得可能です。複数選択が可能な場合は, 「Selected」プロパティで調べます。
■ TListBoxの ListIndexの使用例 procedure TForm1.Button1Click(Sender: TObject); begin if ListBox1.ItemIndex > 0 then begin {選ばれている項目を表示} ShowMessage(ListBox1.Items[ListBox1.ItemIndex]); end; end; procedure TForm1.Button2Click(Sender: TObject); var ix : integer; begin for ix := ListBox1.Items.Count - 1 downto 0 do begin {選択されているか?} if ListBox1.Selected[ix] then begin {メモに追加} Memo1.Lines.Add(ListBox1.Items[ix]); {リストボックスから削除} ListBox1.Items.Delete(ix); end; end; end;