Reading/Writing Config (INIfiles)

BlitzMax Forums/BlitzMax Beginners Area/Reading/Writing Config (INIfiles)

Blitzer101(Posted 2006) [#1]
Hi,

I'm very new to BM, and know this kinda question has been asked before but I've not really found what I'm looking for.

Basically I want to write a funtion(s) to create, read and write to INI files for program config files. Want to be able to reuse the funtions in pretty much any program I write with little or no need to alter them. I see someone has done this pretty much already but I'm kinda using this as a challenge to myself in an effort to learn a bit more about BM.

I have a few idea how to read the data etc. but I'm more concerned ATM about the best way to store the data within the program. i.e. best to use arrays, arrays within arrays, 2 diemensional arrays or types? I started to ready about these but soon had my brains flowing out my ears. :) Any pointers in the best way to achieve what I want would be appreciated.

Thanks in advance. :)


tonyg(Posted 2006) [#2]
It's really going to depend what sort of data it is.
You might want to create a single type called TConfig which has a field for each .ini entry or seperate variables.
You can have arrays, types or lists within the type if your
data needs that particular structure.


Grey Alien(Posted 2006) [#3]
I'm gonna post some blitz plus code later which was my ini file unit. You might be able to convert it?


Blitzer101(Posted 2006) [#4]
tonyg,

I think the main problem I'm thinking of is coding something to deal with an entry within a certain section and making sure that the value is applied under the correct section. e.g.

[SectionName_1]

Pos_X=400
Pos_Y=340
AnotherEntry="Whatever"

[A_DIfferentSection]

Pos_X=120
Pos_Y=200
MoreEntry=10


Now I know it may be unsual for two different sections to have an identical entry under it, but that's what I'm kinda getting at, the flexibility to do so. Hope this makes sense?


Blitzer101(Posted 2006) [#5]
Sorry, should have added that's why I'm having the difficulty in really knowing what kinda code to use, i.e. arrays etc.


Blitzer101(Posted 2006) [#6]
Grey Alien,

Cheers appreciate that, anything that will give me ideas on how to do things is welcome. :)

Sorry for the rushed responses here - only have a few mins - t-break at work. :)