Bonjour,
un inifile c'est pas compliqué..
voilà sa tête avec un exemple bidon..
MyIni.ini
[selection]
dernier=10
avtdernier=10
periode=128
[ChoixSel]
dernier=9
avtdernier=9
periode=254
[premier-dernier]
niveau=2
[systemes]
purge=5844
Ppurge=14
uses
IniFiles; // le uses obligatoire
///////////////////////////////////////////////////////////////////////
/////////// ECRITURE DANS LE FICHIER INI ///////////////////
//////////////////////////////////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var
ini: TIniFile;
begin
// ON CREE L'OBJET
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', 2014);
// Write a boolean value to the INI file.
ini.WriteBool('Section_Name', 'Key_Name', True);
finally
// ON LE LIBERE
ini.Free;
end;
end;
///////////////////////////////////////////////////////////////////////
/////////// LECTURE DANS LE FICHIER INI ///////////////////
//////////////////////////////////////////////////////////////////////
// ON LIT ICI UNE VALEUR
procedure TForm1.Button2Click(Sender: TObject);
var
ini: TIniFile;
res: string;
begin
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;
// ON LIT ICI TOUTES LES 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;
// ON LIT ICI UNE SECTION PARTICULIERE
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;
// ON LIT ICI UNE VALEUR DE SECTION
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;
// ON EFFACE UNE 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;
bien sûr, il existe d'autres méthodes (procédures ou fonctions) applicables au TIniFiles (voir la documentation)
cantador
19 mai 2014 à 12:36
23 mai 2014 à 17:57