如果combobx中有一项为ok,则出现form1,如不是则出现form2.
应该怎么实现?

解决方案 »

  1.   

    什么意思?
    是不是选择OK就显示form1?
      

  2.   

    for i:=0 to ComboBox1.Items.Count-1 do
    begin
      if ComboBox1.Items.Strings[i] = 'ok' then
      begin
        form1.show;
      end
      else begin
        form2.show;
      end;
    end
      

  3.   

    如果是选了ok就form1
    if ComboBox1.Text = 'ok' then
    begin
      form1.show;
    end;
      

  4.   

    if combobox1.text='ok' then
       form1.showmodal
    else
      from2.showmodal;
      

  5.   

    用上面的代码不行,不管选哪个,都有form1,form2出现的
      

  6.   

    procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      if Uppercase(Trim(ComboBox1.Text)) = 'OK' then
      begin
        if Form2 = nil then
          Form2 := TForm2.Create(self);
        Form2.ShowModal
      end else
      begin
        if Form3 = nil then
          Form3 := TForm3.Create(self);
        Form3.ShowModal
      end;
    end;
      

  7.   

    在ComboBox1Change中写,应该可以的亚
      

  8.   

    谢谢 songlian77(八國聯軍) ( )
      

  9.   

    还有一个问题,在运行时向combobox中新加入的一项,想在第二次运行时仍存在,应怎么写。就是想把后加入的永久保存下来,应如何写。combobox.items.add(),只能在运行时保存,第二次运行时有没有了。分可以再给的。
      

  10.   

    还有一个问题,在运行时向combobox中新加入的一项,想在第二次运行时仍存在,应怎么写。form1.ComboBox1.Items.SaveToFile(filename);
    保存from1.combobox1.Items.LoadFromFile(filename);
    登陆
      

  11.   

    如果combobx中有一项为ok,则出现form1,如不是则出现form2.
    应该怎么实现?
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2, Unit3;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var
    i:integer;
    begin
    for i:=0 to 10 do
      begin
      combobox1.items.add(inttostr(i));
      end;
    combobox1.items.add('ok');
    for i:=0 to 10 do
      begin
      combobox1.items.add(inttostr(i));
      end;end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    if combobox1.Items.IndexOf('ok')=-1 then form2.show
    else form3.show;
    end;end.
      

  12.   

    to ghyghost(著名关心CSDN结贴率爱国主义人士代表) 
     谢谢
     有没有不需用到savetofile的方法?
      

  13.   

    combobox.items.add()
    是在程序中动态的添加的,程序关闭,当然就没了。要永久的保存,方法就是将动态添加的信息也保存起来~如savetofile或是保存到数据库的某个字段里,然后在程序启动时再动态的添加进去.