Programs - Ini unit


Aim

The resson for writing the ini unit was when it got to working out the algorithim for changing the values it was acctually quite complicated and it’s good to seperate the code because it allows more flexability.

Method

To read a value from a section was realativly simple, just scan for your section, then look for the setting. If neither were found simply return the default value. That however was the easy part of the programming. To write a value to a file it’s not just as simple as going to that line in the file and replacing it! To change one line the whole file needs to be re-written. So the algorithim for the writing of a value goes as follows:

  • Search for the section and value to write to, all the meanwhile writing all the lines looked at into a temporary file. If we reach the end of the ini-file, forget about it and write the new section header to the temporary file.
  • Write the new ini setting into the temporary file and continue copying the ini-file across into the temporary file.
  • Rename the ini-file to a backup-file, replacing any old backup and rename the temporary file to the ini-file.

Complicated!, even so only four procedures / functions are used: read and write, strings and integers. The interger side uses the string functions but just converts where nessary. That’s all there is to it.