想知道ComboBox的Text中的值是否存在于ComboBox的Items中,ComboBox的Items中的值是从注册表中读出来的。如果不存在就将该值写入注册表,如果存在则退出。如何实现呢?

解决方案 »

  1.   

    if ComboBox1.IndexOf('abc')>=0 then
    ...
      

  2.   

    var
     i:integer;
    begin
     for i:=0 to combobox1.Items.Count-1 do
     begin
       if combobox1.Items.Strings[i]=combobox1.Text then
       showmessage(combobox1.Text);
     end;
    end;
    你看看这段代码,然后再试试看吧
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    VAR
      I:INTEGER;
    begin
      FOR I:=0 TO C2.Items.Count-1 DO
      BEGIN
        IF C2.Items.Strings[I]=C2.Text THEN
        BEGIN
           BREAK;
        END;
      END;
      if i=C2.Items.Count then
        C2.Items.Add(C2.Text);
      //写入注册表
    end;
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    VAR
      I:INTEGER;
    begin  if C2.Items.IndexOf(C2.Text)<0 then
        C2.Items.Add(C2.Text);
      //写入注册表
    end;
      

  5.   

    或者
    procedure TForm1.Button1Click(Sender: TObject);
    begin  if C2.Items.IndexOf(C2.Text)<0 then
        C2.Items.Add(C2.Text);
      //写入注册表
    end;
      

  6.   

    为何报错:Undeclared identifier:"IndexOf"
      

  7.   

    if ComboBox1.items.IndexOf('abc')>=0 then
     在
    else
      不在