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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest way to add & remove records from a text file?

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I have a text file and I would like to know on how to handle the adding and removing of records?
This is on how I read the text file:

Resultpath := GetCurrentDir;
if radiobutton1.checked then
begin
assignfile(f,resultpath+'\process.txt');
{$I-}
Reset(F);
{$I+}
while not eof(f) do
readln(f,datatext);
end;
That should take me at the end of the file. Now how do I add another string to it?
I think there's certainly a better way to handle that.
Thanks.
PO
 
You can use Append to add text to the end of a text file. Otherwise, to add in the middle or remove text, you will have to rewrite the file.
 
You could always use a stringlist...

Use the stringlist.LoadFromFile procedure to load the file into the string list. Append/manipulate the records in the stringlist, then call the saveToFile procedure.

Here is an example:
Take a look at the section:
"Using TStringList to read and write text files
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top