Sections einer Ini-Datei zählen |
|
| System | Win9x, WinNT, Win2000, WinXP, Vista, Win7 |
|---|---|
| Ab Delphi-Version | Delphi 1 |
| Letzte Änderung | 28.09.2010 |
Ini-Dateien enthalten eine oder mehrere Sections, deren Namen in eckigen Klammern stehen. Folgende Funktion zählt diese.
function INISectionsCount(const AFilename: string): Integer;
var ISectionCount: Integer;
i: Integer;
SCurr: string;
SLIni: TStringList;
begin
SLIni := TStringList.Create;
ISectionCount := 0;
try
SLIni.LoadFromFile(AFilename);
if SLIni.Count <> 0 then
begin
for i := 0 to SLIni.Count - 1 do
begin
SCurr := SLIni.Strings[i];
if (SCurr <> '') and (SCurr[1] = '[') and (SCurr[Length(SCurr)] = ']') then
Inc(ISectionCount);
end;
end
finally
SLIni.Free;
end;
Result := ISectionCount;
end;
var ISectionCount: Integer;
i: Integer;
SCurr: string;
SLIni: TStringList;
begin
SLIni := TStringList.Create;
ISectionCount := 0;
try
SLIni.LoadFromFile(AFilename);
if SLIni.Count <> 0 then
begin
for i := 0 to SLIni.Count - 1 do
begin
SCurr := SLIni.Strings[i];
if (SCurr <> '') and (SCurr[1] = '[') and (SCurr[Length(SCurr)] = ']') then
Inc(ISectionCount);
end;
end
finally
SLIni.Free;
end;
Result := ISectionCount;
end;