procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.Add(Edit1.Text);
end;怎样做可以由ListBox1接收add时过滤掉重复的值。
例如:
我在ListBox1中添加了以下几项
Item1
Item2
Item3
...
当我再添加Item1时ListBox1就不接收,如果其中没有相同的话就接收进去。
说的有点晕了,不知道大家看不看得懂,呵呵!!!!

解决方案 »

  1.   

    把要加入的值和已有ListBox1中的Items过行比较,如果有就不加入,否则就加入
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject); 
    var
      Index: Integer;
    begin
      try
        ListBox1.Items.Sorted := True;   { Find will only work on sorted lists! }
        if not ListBox1.Items.Find(Edit1.Text, Index) then
        begin
          ListBox1.Items.Add(Edit1.Text);
        end;
      finally  end;
    end;
      

  3.   

    for xxxxxx
    begin
      if xxx = yyy then
      begin
        showmessage('重复输入');
        exit;
      end;
    end;
      

  4.   


    支持!! listBox1.items.indexof 用空上判斷也可翠。
      

  5.   

    ListBox1.Items.Sorted?不能用啊。。我白高兴啊。
      

  6.   

    ListBox1.Items.Find???又是怎么回事。
      

  7.   

    procedure TForm1.Button11Click(Sender: TObject);
    var
      Index: Integer;begin
      try
        Index := ListBox1.Items.IndexOf(Edit1.Text);
        if Index = -1 then
        begin
          ListBox1.Items.Insert(Index, Edit1.Text);
        end;
      finally  end;end;
    try it