Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INI File - deleting entries 1

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm writing a Delphi 5 application thats reading/writing to an 'INI' file using the 'ReadString'/'WriteString', 'ReadInteger'/'WriteInteger' functions - is there any method that will delete existing entries in the 'INI' file that will be written to ?
Thanks in advance
Steve
 
StevenK,

Interesting question. The only thing that I can think of would be to load that sucker into a tStrings object, locate the line in question, nuke it, and then resave the file.

Let me know if you need an example. A simple reply should suffice.

Hope this helps...

-- Lance
 
footpad : I'm following something like this logic at the moment in the sense that I'm writing strings/integers to the INI file from StringLists (which are initially loaded with values from the INI file at start-up). Say for instance I start with 4 values (as read from the INI file) and I delete 2 in the cycle of my application when I cycle the list I'm over-writing the first 2 entries but entries 3 and 4 remain in the INI file and will be re-loaded again at start-up the next time round (by which point the entries are redundant and the 'live' entries have been re-indexed). Am I looking at my original idea of creating a copy of the INI file at start-up (Test_BU.ini) and when I come to close the application delete the original (Test.ini) and save the INI file as new ?
Steve
 
StevenK,

It really depends on how you want to handle it. Personally, I'd probably rewrite the INI file at the end of the INI process and refresh any internal copies of the settings (e.g. re-read the file).

The nice thing about keeping a backup copy is that you can provide a Revert Settings command up to the point they actually exit the program. It's a nice touch I appreciate in graphics packages, but it's not commonly used in other things.

Depending on your users, that may or may not be an advantage. If you can, it might help to ask a few whether or not they'd find such a thing useful. They'll probably say "no," but I think that sort of nicety is like embedding an "in-joke" into a manuscript example. 99 out of 100 readers may miss it, but that 100th one makes it worth while.

Hope this helps...

-- Lance
 
Thanks for the advice on this one people - I've resorted to taking a backup prior to deleting and recreating the INI file and this seems to work OK.
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top