use ...,inifiles;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
  ini:Tinifile;
begin
  ini:=Tinifile.Create('c:\test.ini');
  for i:=0 to self.ListBox1.Items.Count-1 do
  begin
    ini.WriteString('test',inttostr(i+1),ListBox1.Items.Strings[i]);
  end;
  ini.Free;
end;
  

解决方案 »

  1.   

    写入:
    var
      I:Integer;
    begin
      with TIniFile.Create(IniFileName) do begin
        for I:=0 to ListBox1.Items.Count-1 do
           WriteString('ListBox',IntToStr(I),ListBox1.Items.Strings[I]);
        Free;
        end;
    end;
    写入的格式如下:
    [ListBox]
    0=String
    1=String
    ......读取:      
    var
      SL:TStringList;
      I:Integer;
    begin
      SL:=TStringList.Create;
      with TIniFile.Create(IniFileName) do begin
        ReadSection('ListBox',SL);
        for I:=0 to SL.Count-1 do
          ListBox1.Items.Add(ReadString('ListBox',SL.String[I],''));
        Free;
        end;
    end;以上是基本思路,可以稍做修改,比如上面写入的键名是从0开始的数字,你可以换成其它字符,读取的时候仍可以正确读取。