如何将ini配置文件中的小节名在ListBox中显示出来?

解决方案 »

  1.   

    var
      StrList: TStringList;
      i: integer;
      Str: String;
    begin
      StrList := TStringList.Create;
      for i := 0 to StrList.Count - 1 do 
      begin
       Str := Trim(StrList.String[i]);
       if Str[1] <> '[' then
         ListBox1.items.add(Str);
      end; 
    end;
      

  2.   

    pankun(剑神一笑)
    回答的漂亮 佩服
      

  3.   

    啊, angle097113兄言重了:)
    上面有个问题哈,开始急着回答忽略了,呵呵StrList没释放
    加上StrList.Free
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    strLine,stradd:string;
    i,j:integer;
    F: TextFile;
    begin
      try
        AssignFile(F, 'c:\1.ini');
        Reset(F);
      except
        Showmessage('err');
      end;  strLine := '';
      while not eof(F) do begin
        Readln(F, strLine);
        if trim(strLine) = '' then begin
          Continue;
        end else begin
        i:=pos('[',strline);j:=pos(']',strline);     if (i> 0) and (j> 0) then  begin
            stradd:=copy(strline,i+1,j-i-1);
            if stradd='' then continue;
            listbox1.Items.Add(stradd);      end
          else continue;     end;
    end;
    end;
    调试通过,保证能用
      

  5.   

    方法很简单:
    var
      Ini: TIniFile;
    begin
      Ini := TIniFile.Create('xxx.ini');
      Ini.ReadSections(ListBox1.Items);
      Ini.Free;
    end;