我做了个程序里面用到了许多TComboBox控件,需要在窗体的OnActivate事件里将ini文件相应项目中的内容写到每一个TComboBox控件中,我想能不能共用同一个过程将这些项目中的内容写到相应的TComboBox控件中。多谢!

解决方案 »

  1.   

    当然可以,用combobox1.items作为参数传递。
      

  2.   

    用TActionList;
    在TActionList中添加一个TAction,
    在TAction的onExecute事件中写你的操作
      

  3.   

    不明白你的Ini里是什么内容,但是你的想法是可以实现的,给你个例子做参考:procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
    begin
        for i:=1 to 4 do
            Tcombobox(self.FindComponent('combobox'+inttostr(i))).Items.Add(inttostr(i));
    end;
      

  4.   

    其中的i和add的内容可以换成你自己的代码
      

  5.   

    是这样的,我的ini文件结构如下
    [section]
    a=1,2,3,4,5
    b=6,7,8,9,10我程序中有两个ComboBox,要在ComboBox1中添加ini文件a中的内容,在ComboBox2中添加ini文件b中的内容
      

  6.   

    我不想重复写相似的重复代码,因为程序中有很多的ComboBox,我想能否写一个过程将ComboBox的名字、ini文件中的项目名称作为参数传递
      

  7.   

    创建解析函数
    function AA(const Value : String):TStringList;
    var
      S :String;
      p , Start :PChar;
    begin
      Result := TStringList.Create;
      p := pointer(Value);
      if p <> nil then
      begin
        while p^ <> #0 do
        begin
          Start := p;
          while not (p^ IN [',',#0]) do
          begin
            Inc(p);
          end;
          SetString(S, Start, P - Start);
          Result.Add(s);
          if P^ = ',' then Inc(P);
        end;
      end;
    end;创建过程
    procedure BB(Const Section,Ident : String; const combo:TComboBox);
    var
      MyIni : TIniFile;
      A : TStringList;
      i:Integer;
    begin
      combo.Items.Clear;
      MyIni := TIniFile.Create('.\Test.Ini');
      A := TStringList.Create;
      A := AA(MyIni.ReadString(Section,Ident,''));
      for i:=0 to A.Count-1 do
        combo.Items.Add(A.Strings[i]);
      MyIni.Free;
    end;调用过程
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      BB('section','a',ComboBox1);
    end;