比如某ini文件小节名为Section,关键字为Key1,Key2,Key3,Key4,...:
[Section]  
Key1=a
Key2=b
Key3=c
Key4=d  
...请问如何才能统计读出Section下关键字Key[i](i=0,1,2,...k)的个数?

解决方案 »

  1.   

    TIniFile类有个ReadSection方法,可以读出指定段下的所有行的名称。如:
    var pList: TStringList;
    ...
    pIni.ReadSection('Section', pList);
    pList.Count就是行数,每一行的内容在pList.Strings[i]中,读取其内容用pIni.ReadString('Section', pList.Strings[i], '');
    ...
      

  2.   

    可是系统为什么提示[Warning] Variable 'pList' might not have been initialized?能告诉我是什么意思,怎么解决吗?谢了:)
      

  3.   

    TIniFile类有个ReadSection方法,可以读出指定段下的所有行的名称。如:
    var pList: TStrings;
    ...
    begin
      pList := TStringList.Create;
    pIni.ReadSection('Section', pList);
    pList.Count就是行数,每一行的内容在pList.Strings[i]中,
    读取其内容用pIni.ReadString('Section', pList.Strings[i], '');