delphi从 INI 文件中读取所有部分并添加到列表中  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi从 INI 文件中读取所有部分并添加到列表中


使用TIniFile.ReadAllSections将所有部分的名称检索到TStrings后代中,这可能是ComboBox.Items.


ComboBox1.Items.Clear;

Ini.ReadAllSections(ComboBox1.Items);


用法:

[1038]

AValue = a1 

BValue = b1

CValue = c1

DValue = d1


[1031]

AValue = a2 

BValue = b2

CValue = c2

DValue = d2

I use this procedure for filling the grid:


procedure TForm1.ReadIntoGrid(const aIniFileName, aSection: string;

const aGrid: TStringGrid);

var

  Ini: TIniFile;

  SL: TStringList;

  i: Integer;

begin

  SL := TStringList.Create;

  try

    Ini := TIniFile.Create(aIniFileName);

    try

      aGrid.ColCount := 2;

      Ini.ReadSectionValues(aSection, SL);

      aGrid.RowCount := SL.Count;


      for i := 0 to SL.Count - 1 do

      begin

        aGrid.Cells[0,i] := SL.Names[i];

        aGrid.Cells[1,i] := SL.ValueFromIndex[i];

      end;

    finally

      Ini.Free;

    end;

  finally

    SL.Free;

  end;

end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.044843912124634 seconds