请教:
我需要读取 ini 文件中的所有 小节,我怎么知道有多少个小节呢?
假设文件名为 : my.ini可能是:
[L1]
AA=11
BB=22
[L2]
AA=11
BB=22
[L3]
AA=11
BB=22也可能是 
[L1]
AA=11
BB=22
[L2]
AA=11
BB=22我怎么知道有多少个小节呢?谢谢!

解决方案 »

  1.   

    procedure TForm2.Button1Click(Sender: TObject);
    var
      f: TIniFile;
      s: TStrings;
    begin
      f := TIniFile.Create('my.ini');  s := TStringList.Create;
      f.ReadSections(s);  ShowMessage('节数:' + IntToStr(s.Count));
      s.Free;
      f.Free;
    end;
      

  2.   

    TIniFile类的方法 ReadSections 可以读出所有的Sections
      

  3.   

    继续向大哥请教个 小节里有多少个关键字?
    比如:
    可能是:
    [L1]
    AA=11
    BB=22也可能是 
    [L1]
    AA=11
    BB=22
    CC=33怎么知道这个小节有多少个关键字啊?
      

  4.   

    uses IniFiles;
    procedure TForm1.FormActivate(Sender: TObject);var
      AppIni: TIniFile;
      Num: Integer
    begin
      AppIni := TIniFile.Create('WIN.INI');
      AppIni.ReadSections(ListBox1.Items);
      Num := ListBox1.Items.Count;
      AppIni.Free;by the way
    think and try and lookup the Help before ask