Hur laddar man lättast info från en ini-fil?
EX. man vill ladda storleken från raden size=
ini-fil
4 svar · 265 visningar · startad av msossna
Som vanligt är det enklas att kolla i hjälpen ;) Delphi har en mycket bra hjälp.
This example reads strings in the DELPHI32.INI file and displays them on the form.
Before you run this example, you must add the IniFiles unit to the uses clause of your unit.procedure TForm1.FormActivate(Sender: TObject);
var
DelphiIni: TIniFile;
begin
Canvas.TextOut(20, 10, 'VARIOUS DELPHI SETTINGS');
DelphiIni := TIniFile.Create('Delphi32.Ini');
with DelphiIni do
begin
with Canvas do
begin
TextOut(10, 50, 'Editor Font = ' +
ReadString('Editor', 'FontName', 'ERROR'));
TextOut(10, 70, 'Search Path = ' +
ReadString('Library', 'SearchPath', 'ERROR'));
TextOut(10, 90, 'Component Library = ' +ReadString('Library', 'ComponentLibrary', 'ERROR')); TextOut(10, 110, 'VBX Directory = ' + ReadString('VBX', 'VBXDir', 'ERROR')); TextOut(10, 130, 'VBX Unit Directory = ' + ReadString('VBX', 'UnitDir', 'ERROR')); end;end;
DelphiIni.Free;
end;
Hjälpen är bra och stor och halvt hopplös att hitta i :)
Dessutom förstår jag inte exemplet till 100% :q
fil.ini:
[info]
size=10
Kod:
uses Inifile;
Procedure ReadIni();
var
IniFile: TIniFile;
size: integer;
begin
IniFile := TIniFile.Create('fil.Ini');
size := IniFile.ReadInteger('Info', 'size', 0));
IniFile.Free;
end;
Tack, nu förstår jag hur det fungerar, det var ju inte så avancerat :)