| Delphi provides useful function to access INI file. With TIniFile class, you can read and write easily.
Below is the simple example writing INI files.
uses inifiles;
...
procedure Tform1.Button1Click(Sender:TObject);
var
myIniFile:TIniFile;
begin
myIniFile:=TIniFile.Create(ChangeFileExt( Application.Exename,'.ini'));
try
myIniFile.WriteString('CompanyInfo','CompanyName','mindfire');
myIniFile.WriteInteger('CompanyInfo',' IntVal',100);
finally
myIniFile.Free;
end;
end;
And below is the example to read data from INI file.
uses inifiles;
...
procedure Tform1.Button2Click(Sender:TObject);
var
myIniFile:TIniFile;
sVal:string;
iVal:integer;
begin
myIniFile:=TIniFile.Create(ChangeFileExt( Application.Exename,'.ini'));
try
sVal:= myIniFile.ReadString('CompanyInfo,'CompanyName','No Value');
iVal:=myIniFile.ReadInteger('CompanyInfo,'IntVal',0);
ShowMessage(sVal + IntToStr(iVal));
finally
myIniFile.Free;
end;
end;
As you can see above, you can read and write data with methods. ReadString is for reading string type format from INI file, ReadInteger is for reading integer type data. |