例如有变量a,值为a1,a2,a3 我想在combox组件设定默认值为a1,a2,a3中某个值 ,但是a的值根据程序给定,怎么做??

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      a:String;
    begin
      ComboBox1.Clear;
      ComboBox1.Items.Add('a1');
      ComboBox1.Items.Add('a2');
      ComboBox1.Items.Add('a3');
      a:=ComboBox1.Text;
    end;
      

  2.   


    ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(a);
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      ComboBox1.Items.Clear;
      for i:=0 to 3 do
        ComboBox1.Items.Add('a'+inttostr(i));
      ComboBox1.ItemIndex:=0;
    end;
      

  4.   

    procedure TForm1.aaa(str: string);
    var
      i:integer;
    begin
      ComboBox1.Items.Clear;
      for i:=0 to 3 do
        ComboBox1.Items.Add(str+inttostr(i));
      ComboBox1.ItemIndex:=0;
    end;
      

  5.   

    例如有变量a,值为a1,a2,a3 我想在combox组件设定默认值为a1,a2,a3中某个值 ,
    但是a的值根据程序给定,怎么做??你先确定你要默认哪个值(a1,a2,a3)是comboBox的第N项,
    ComboBox.ItemIndex := N-1 ; //设默认值
    a  := ComboBox.Text ;//这样子不就得到ComboBox的值啦