begin
k:=736; s:='Okey'; td:=now;
path_pr:=ExtractFilePath(application.exename) +'tsn.ini';
t_Ini := TIniFile.Create(nfile);
try
with t_Ini do begin
WriteInteger('TSN', 'str1', k);
WriteFloat('TSN', 'str2', 736.123);
WriteString('TSN', 'str3', s);
WriteDate('TSN', 'str4', strtodate('01.02.2012'));
WriteTime('TSN', 'str5', td);
Writebool('TSN', 'str6', true);
end;
except
showmessage('Нет доступа к Ini-файлу !');
end;
t_Ini.Updatefile; t_Ini.Free;
end;
Рассмотрим на примере процедуру считывания ранее сохраненной информации из Ini-файла:
procedure TForm1.Button4Click(Sender: TObject);
var t_Ini: TIniFile;
k: integer; s, path_pr, nfile: string; td: tdatetime;
begin
path_pr:=ExtractFilePath(application.exename) +'tsn.ini';
t_Ini := TIniFile.Create(nfile);
try
with t_Ini do begin
k:=ReadInteger('TSN', 'str1', -1); showmessage(inttostr(k));
s:=ReadString('TSN', 'str3', '-1'); showmessage(s);
td:=ReadDate('TSN', 'str4', strtodate('1.1.2000'));
showmessage(datetostr(td));
showmessage(floattostr(ReadFloat('TSN', 'str2', -1.123)));
showmessage(timetostr(ReadTime('TSN2', 'str5', now)));
showmessage(inttostr(byte(ReadBool('TSN2', 'str6', false))));
end;
except
showmessage('Нет доступа к Ini-файлу !');
end;
t_Ini.Free;
end;