PDA

View Full Version : .ini-file loading algorithm



FlyingFish
23-11-2003, 05:10 PM
hi there!

In my game I want to save a lot of values in .ini-files.

I want to let the inis look like this:

[title] //for example name of an object

property=value
property=value
..

BTW: the unreal engine does it like this.

Now I need to write an algorithm which loads the values and "connects" them with the right properties.
That is maybe not so hard to do, but I don not have an idea how to make the algorithm easy and comfortable to use and that for more than one .ini-file.

I hope you understood my problem. I'm grateful for any help,

sven

Paulius
23-11-2003, 06:31 PM
Check out this tutorial http://www.alistairkeys.co.uk/files2.shtml by Alimonster.

Ultra
23-11-2003, 10:16 PM
If you're not afraid of the VCL you can use the Inifiles unit.

Then all you need to do is this:

procedure Save;
var
Ini: TIniFile;
a,b: Integer;
s: String;
// you can use other types also
begin
a := 12;
b := -85;
s := 'hello';

Ini := TIniFile.Create('MyIni.ini');
try
// title property value
Ini.WriteInteger('Something', 'A', a);
Ini.WriteInteger('Something', 'B', b);
Ini.WriteString ('Something', 'S', s);
finally
Ini.Free;
end;
end;

procedure Load;
var
Ini: TIniFile;
a,b: Integer;
s: String;
begin
Ini := TIniFile.Create('MyIni.ini');
try
// title property defaultvalue
Ini.ReadInteger('Something', 'A', 1000);
Ini.ReadInteger('Something', 'B', 99);
Ini.ReadString ('Something', 'S', 'test');
finally
Ini.Free;
end;
end;
end;

FlyingFish
25-11-2003, 06:49 PM
Thanx a lot guys, that helps! :D

sven