procedure TForm1.Button2Click(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to 999 do
    listbox1.Items.Add(inttostr(i));
  Form1.Caption:='共'+inttostr(listbox1.Items.Count)+'项';  for i:=0 to listbox1.Items.Count-1 do
    if listbox1.Items.Strings[i]<'555' then
      listbox1.Items.Delete(i);
  Form1.Caption:='共'+inttostr(listbox1.Items.Count)+'项';
end;

解决方案 »

  1.   

    在删除的过程中ListBox1.Items.Count是改变的,
    当你删除500条纪录的时候就应该跳出循环了
    而且当你删除记录后listbox1.Items.Strings[i]
    也不是你预想中的记录了,
    比如你删除了第[2]条记录,记录[4]指的是原来记录[5]
    这同数组不一样
    你的程序设计思路有问题,改一个方法吧
    :)
      

  2.   

    listbox1.Items.Strings[i]<'555' 好像不能够判断吧。
      

  3.   


      for i:=listbox1.Items.Count-1 downto 0 do
      ....
      

  4.   

    listbox1.Items.Strings[i]<'555' 只是我随手写的,无关紧要我试着改了代码,删除表项从后往前删就可以了。不知这是不是正确的方法。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      for i:=0 to 999 do
        listbox1.Items.Add(inttostr(i));
      form1.Caption:=inttostr(listbox1.Items.Count);  for i:=listbox1.Items.Count-1 downto 0 do
        if (strtoint(listbox1.Items.Strings[i]) mod 2=0) then
          listbox1.Items.Delete(i);
      Form1.Caption:='共'+inttostr(listbox1.Items.Count)+'项';
    end;end.