Работа с INI-файлами
Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch
{
An INI file stores information in logical groupings, called “sections.”
Within each section, actual data values are stored in named keys.
[Section_Name]
Key_Name1=Value1
Key_Name2=Value2
}
uses
IniFiles;
// Write values to a INI file
procedure TForm1.Button1Click(Sender: TObject);
var
ini: TIniFile;
begin
// Create INI Object and open or create file test.ini
ini := TIniFile.Create('c:\MyIni.ini');
try
// Write a string value to the INI file.
ini.WriteString('Section_Name', 'Key_Name', 'String Value');
// Write a integer value to the INI file.
ini.WriteInteger('Section_Name', 'Key_Name', 2002);
// Write a boolean value to the INI file.
ini.WriteBool('Section_Name', 'Key_Name', True);
finally
ini.Free;
end;
end;
// Read values from an INI file
procedure TForm1.Button2Click(Sender: TObject);
var
ini: TIniFile;
res: string;
begin
// Create INI Object and open or create file test.ini
ini := TIniFile.Create('c:\MyIni.ini');
try
res := ini.ReadString('Section_Name', 'Key_Name', 'default value');
MessageDlg('Value of Section: ' + res, mtInformation, [mbOK], 0);
finally
ini.Free;
end;
end;
// Read all sections
procedure TForm1.Button3Click(Sender: TObject);
var
ini: TIniFile;
begin
ListBox1.Clear;
ini := TIniFile.Create('MyIni.ini');
try
ini.ReadSections(listBox1.Items);
finally
ini.Free;
end;
end;
// Read a section
procedure TForm1.Button4Click(Sender: TObject);
var
ini: TIniFile;
begin
ini: = TIniFile.Create('WIN.INI');
try
ini.ReadSection('Desktop', ListBox1.Items);
finally
ini.Free;
end;
end;
// Read section values
procedure TForm1.Button5Click(Sender: TObject);
var
ini: TIniFile;
begin
ini := TIniFile.Create('WIN.INI');
try
ini.ReadSectionValues('Desktop', ListBox1.Items);
finally
ini.Free;
end;
end;
// Erase a section
procedure TForm1.Button6Click(Sender: TObject);
var
ini: TIniFile;
begin
ini := TIniFile.Create('MyIni.ini');
try
ini.EraseSection('My_Section');
finally
ini.Free;
end;
end;
|