ListCount(ListBoxなど)


ListCountプロパティは ListBoxコントロールの総数を返します。Delphiでは, TStringsクラスの「Count」プロパティで取得可能です。例えば TListBoxコンポーネントの Itemsプロパティは TStrings型ですので, ListBox1.Items.Count で得ることができます。また, ComboBoxや Memo, RichEditの各 Items, Linesプロパティも TStrings型なので Countプロパティを使用できます。

■ TListBoxの Countの使用例
  procedure TForm1.Button1Click(Sender: TObject);
  var
    ix  : integer;
  begin
    {画面への更新抑制}
    ListBox1.Items.BeginUpdate;
    {内容クリア}
    ListBox1.Items.Clear;
    {ファイルから読み込み}
    ListBox1.Items.LoadFromFile('c:\sample.txt');
    {項目の内容を調べる}
    for ix  :=  ListBox1.Items.Count - 1 downto 0 do  begin
      {項目の内容に*が含まれていたら削除}
      if  Pos('*',ListBox1.Items[ix]) > 0 then  begin
        ListBox1.Items.Delete(ix);
      end;
    end;
    {画面への更新抑制解除}
    ListBox1.Items.EndUpdate;
  end;