阅读IniFile的2行

Lak*_*erw 4 delphi ini

再试一次.根据建议,添加我理解的代码片段.我很好,我必须在两行中保存4位信息,如下所示:

IniFile.WriteString('TestSection','Name','Country');
IniFile.WriteString('TestSection','City','Street');
Run Code Online (Sandbox Code Playgroud)

我的问题更多的是将这些信息重新加载到表单中.如果在我的IniFile中我保存了例如以下代码

[TestSection]
John=Uk
London=barlystreet
Mike=Spain
Madrid=eduardostrata
Emma=USA
New York=1st Avenue
Run Code Online (Sandbox Code Playgroud)

在IniFile中编写信息.通过上面的代码添加.现在我的问题是:当我输入编辑框Mike时,我可以加载其他所有信息.(西班牙,马德里,eduardostrata).

Ken*_*ite 15

这不是INI文件的工作原理.您保存name=value对,并且必须有一种方法来关联它们.

也许这可以帮助您入门:

Ini := TIniFile.Create(YourIniFileName);
try
  Ini.WriteString('Mike', 'Country', 'Spain');
  Ini.WriteString('Mike', 'City', 'Madrid');
  Ini.WriteString('Mike', 'Street', 'EduardoStrata');
finally
  Ini.Free;
end;
Run Code Online (Sandbox Code Playgroud)

包含以下内容的INI文件中的结果:

[Mike]
Country=Spain
City=Madrid
Street=EduardoStrata
Run Code Online (Sandbox Code Playgroud)

要加载:

var
  Country, City, Street: string;
  Ini: TIniFile;
begin
  Ini := TIniFile.Create(YourIniFilename);
  try
    Country := Ini.ReadString('Mike', 'Country', '<None>');
    City := Ini.ReadString('Mike', 'City', '<None>');
    Street := Ini.ReadString('Mike', 'Street', '<None>');
  finally
    Ini.Free;
  end;
  // Country, City, and Street now equal the values for 'Mike',
  // or they contain '<None>' if the section 'Mike' doesn't
  // exist or has no values for the variable.
end;
Run Code Online (Sandbox Code Playgroud)

所以你可以弄清楚它是如何工作的.部分([]中的部分)是人的名字,名称/值对是位置和它的对应值(例如,'Country = Spain').

  • 您还想提及我认为的ReadSections. (2认同)