PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

INI File Library

PointOfLight · 16 Sep 2004, 19:20 UTC
Here are the list of functions so far (bold are coded - but not necessarily working 8O ):


    func IniFile_SectionExists(list$, section$)
    func IniFile_Open(filename$, list$)
    func IniFile_WriteChanges(filename$, list$)
    func IniFile_ReadString(list$, section$, key$, default$)
    func IniFile_ReadInteger
    func IniFile_ReadFloat
    func IniFile_WriteString(list$, section$, key$, value$)
    func IniFile_WriteInteger
    func IniFile_WriteFloat
    func IniFile_EraseSection(list$, section$)
    func IniFile_ListKeys(list$, section$, key_list$)
    func IniFile_ListSections(list$, section_list$)


My question is: is there really a need for 3 different read / write functions? Truth is, all the data is really in string format in an INI file anyway, and the user could easily convert values back and forth once they've read the value out of the file. If there is truely a precieved value to the additional read / write functions (besides string) I will add them, but I just thought I'd get some feedback.[/b]
No don't, I wasn't really thinking when I wrote this. I looked at the ini functions from delphi at the time.

I am impressed, PPL will be able to do INI files pretty easily. :D
Likewise agree that the conversion functions should be outside the INI library
How is the library coming along? Any chance to see a beta soon? :wink:
PointOfLight · 17 Sep 2004, 19:22 UTC
Actually, I think I had it pretty much wrapped up last night (including a small but functional INI editor as a sample). I've just been wanting to give it a final run through, and I've actually been busy at work today :( I will try and get it posted tonight (Friday).
We you post it, can you show the example (or a small amount of code) in the post to show users how easy it is to use .ini files with PPL? It would be easier than having to download the .zip file just to get an idea. Thanx. I think it's a great addition to PPL.
PointOfLight · 17 Sep 2004, 21:37 UTC
Here's the first beta. I think there are still a couple of problems, but I believe it's actually from the sample, not the library. As for using it, it goes something like this:

Code:

//The library reads the whole file into a list,
// so ini$ will be a, well, list!
IniFile_Open("test.ini", &ini$);
value$ = IniFile_ReadString(ini$, "Section1", "Key1", "default");
if(Int(value$) < 10)
IniFile_WriteString(&ini$, "Section1", "Key2", "Less Than Ten");
else
IniFile_WriteString(&ini$, "Section1", "Key2", "A Big Number");
end;
IniFile_WriteChanges("test.ini", ini$);


That's all there is to it! Download the file for more INI goodness. I will add a section to the help file documenting this library, in addition to all the other libraries I've contributed over time.

One final thing to note is that the current version of ini_lib.ppl also requires misc_lib.ppl. This requirement will go away as soon as I fix ini_lib to use the now built-in trim function!

Enjoy :D
Attachments:
ini.zip (8 KB)
Hi,

That is some cool library. However there is one thing I think would make more sense:

ini$ = IniFile_Open("Filename");

Would be more like the standard functions (fopen...). What do you think?

And what about making the function names more like:

IniOpen
IniRead
IniWrite
IniClose (previously IniFile_WriteChanges)

I think it would be a lot better to use and nicer. Let me know what you think.
PointOfLight · 18 Sep 2004, 04:17 UTC
I don't have a problem making any of those changes. The main reason I passed the list through as a parameter on the Open function was because I passed it through as a parameter everywhere else, but returning the list instead would not be an issue. The naming convention was simply to follow suit with the other libraries I've created (ComboBox_, ListBox_, etc.). But again, I'm all for what the user wants :D
PointOfLight · 18 Sep 2004, 05:33 UTC
I'm trying to implement the ini$ = IniOpen method, but can't seem to get it to work. How do I get a function to return a list? If I just do return(list$), then ini$ is just a string, not a list.
Oh, damn it. Yes this is something I have to look into. Sorry then, use your own method until maybe later when it is implemented correctly.

Return(), return values and not actual variables.
PointOfLight · 18 Sep 2004, 14:05 UTC
Here's the latest version. The names have been changed to protect the innocent. I also tweaked a couple of minor things in the sample. Hope someone finds this useful.
Attachments:
initest.zip (7 KB)
Eric,

I'm sure people will find it useful. I'm going to try it out myself. Thanks!

Brad