PDA

View Full Version : WriteINI(), ReadINI() tutorial



mc_teo
05-04-2009, 07:21 PM
This is my first tutorial, on a handy little procedure.

WriteINI() is a very nice, and easy way to save peoples settings from a DeclarePlayers Procedure.

The format is:


WriteINI(Section, Key, Value, FilePath);

Value := ReadINI(Section, Key, FilePath);




A section can be used for different players.
the key would be like 'user', and the value would be the username.

this is best inplimented in forms, for a save and load button.

A working example:


program SaveAndLoad;

const
Info = 'Information_goes_here';

var
filename:string;
Value:string;

procedure Save;
begin
WriteINI('TestSection', 'TestKey', Info, FileName);
end;

procedure Load;
begin
Value := ReadINI('TestSection', 'TestKey', Filename);
end;

begin
FileName := AppPath + 'Scripts\settings.ini';
Save;
Load;
WriteLn(Value);
end.


So this saves the Info into 'Scripts/settings.ini' in the format of


[TestSection]
TestKey=Information_goes_here

and loads it to write it out.

this could be put behind a "Save" button on a form to save it all, so next time you would only have to load it, by pressing "Load"...



DeleteINI(Section, Key, FilePath);


This deletes the Key passed to it and the Value associated with it.



Anyways, this is my first tutorial...

Please leave me any comments

EvilChicken!
05-04-2009, 09:31 PM
Thanks for making this tutorial, I'll probably redirect people who want to find out more about INIs to this tutorial in a project I'm working on as we speak. It would be really great if you could add more info into it.
Take a look at Wikipedia, for instance - there's a great article about INI files there.

Oh, and from looking at your signature, it seems as you want rep.
Enjoy 3 new reputation points from me.

Da 0wner
05-05-2009, 05:07 PM
Enjoy 4 new reputation points from me even though I already have my own :D.

ShowerThoughts
05-05-2009, 05:24 PM
I use Ini files all the time, but I am going to switch to register since I am able to acces that and scar isn't, but scar is very good for ini files!
Do you have a question, you can also ask me.
Note: Ini files aren't that complicated ;)

Shuttleu
05-10-2009, 04:56 PM
change them to scar tags
and change WriteINI(Section, Key, Value, FilePath);

Value := Read(Section, Key, FilePath);
to WriteINI(Section, Key, Value, FilePath);

Value := ReadINI(Section, Key, FilePath);
very good

now add a bit of info about DeleteINI and how its used and what it does etc.

~shut