Reputation: 68054
Delphi's RTL has a tantalizing function: TCustomIniFile.ReadSubSections
But this doesn't really seem to be properly explained anywhere.
ReadSubSections
, how do you use the result to read data from a particular subsection?Upvotes: 2
Views: 4656
Reputation: 1968
To write subsections just join your section name and subsection name with a backslash.
[section_name\subsection_name]
procedure Foo;
var
LIniFile: TIniFile;
slValues: TStringList;
IniFileName: string;
begin
IniFileName := ''; //your ini file
LIniFile := TIniFile.Create(IniFileName);
try
//SECTION = MAINSECTION
//SUBSECTIONS = SUBSECTION_A
// = SUBSECTION_B
LIniFile.WriteString('MAINSECTION\SUBSECTION_A','IDENT','A');
LIniFile.WriteString('MAINSECTION\SUBSECTION_B','IDENT','B');
slValues := TStringList.Create;
try
LIniFile.ReadSubSections('MAINSECTION', slValues);
//slValues.count = 2
//slValues.strings[0] = SUBSECTION_A
//slValues.strings[1] = SUBSECTION_B
// do your stuff here!
finally
slValues.Free;
end;
finally
LIniFile.Free;
end;
end;
the ini file looks like:
[MAINSECTION\SUBSECTION_A]
IDENT=A
[MAINSECTION\SUBSECTION_B]
IDENT=B
Upvotes: 4