Hola walterk.
olbeup te dió un muy buen ejemplo, pero ya escribí el código, así que te agrego otro
En este se seleccióna el mayor número del valor de la sección "Area" y se añade otra sección con el valor incrementado (sigo en dudas si deseas agregar una nueva o modificar el valor de la existente).
Código Delphi
[-]
...
implementation
uses IniFiles;
const
FNAME = 'c:\tmp\Areas.ini';
procedure AddNextSection(const FileName: TFileName);
var
Sections : TStringList;
Values : TStrings;
IniFile : TMemIniFile;
NewArea,s : string;
i, max : Integer;
begin
IniFile := TMemIniFile.Create(FNAME);
try
Sections := TStringList.Create;
Values := TStringList.Create;
try
IniFile.ReadSections(Sections);
Sections.Sort;
NewArea := Sections[Sections.Count-1];
IniFile.ReadSectionValues(NewArea, Values);
max := Pos('.', NewArea);
max := StrToIntDef(Copy(NewArea, max+1, Length(NewArea)-max+1), 0);
Inc(max);
NewArea := Format('Area.%d', [max]);
for i := 0 to Values.Count-1 do begin
s := Values[i];
if Pos('Layer=', s) <> 0 then s := Format('Layer=%d',[max]);
IniFile.WriteString(NewArea, Copy(s, 1, Pos('=',s)-1),
Copy(s, Pos('=',s)+1, MaxInt));
end;
IniFile.UpdateFile;
finally
Values.Free;
Sections.Free;
end;
finally
IniFile.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddNextSection(FNAME);
end;
(*) Se podría simplificar con el método
IndexOfName pero Delphi 7 carece de
StrictDelimiter y toma el espacio como delimitador.
Saludos