Forum > General

Can I edit a text file or do I have to delete it and recreate it?

(1/2) > >>

wpflum:
I'm using a straight text ini file to set defaults in a program I'm writing and I want to be able to allow the user to change the defaults.  I have the code in place to change the running variables that effect the changes but I'm not sure the best way to go about getting those changes back into the ini file.  Is there a way I can read in a line, change it, and write it back out or will I have to delete the original ini file and recreate it each time a change is made?

Bill

theo:
Use TIniFile:
http://delphi.about.com/od/objectpascalide/a/tinifile.htm

wpflum:
I had looked at that briefly but I thought I saw someplace that it was based on a windows ini format not a straight text format?  Right now I have what I need working but I still might look at the tinifile include.

Thanks

bobc:

--- Quote from: wpflum on September 01, 2010, 03:29:36 pm ---Is there a way I can read in a line, change it, and write it back out or will I have to delete the original ini file and recreate it each time a change is made?

--- End quote ---
There is not really a practical way to rewrite parts of a text file, unless for example you use a fixed line length and pad with spaces. You don't need to delete the file though, you can reopen it with write access and write the new data.

wpflum:
I found the 'rewrite' function and that is what I'm using right now and it seems to be working.  I would like to look into th tinifile at some point just to see if I can shorten the code up.

Navigation

[0] Message Index

[#] Next page

Go to full version