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

Add a line in a text file

Status
Not open for further replies.

fll

Programmer
May 7, 2002
30
0
0
BE
How to add a line in the end of a text file?

I tried

var
tt:text;
l:string;
begin
...
assignfile(tt,'text.txt');
reset(tt);
while not eof (tt) do
readln (tt,l)
...
writeln(tt,'blablabla');
...
Closefile(tt);
...
end;

Thanks in advance...
Laurent.

;-)
 
If you only need to write to a file, then you should use Append instead of Reset. If you need both reading and writing then you'd have to do it in two steps:
Code:
var
  tt:text;
  l:string;
begin
  ...
  assignfile(tt,'text.txt');
  reset(tt);
  while not eof (tt) do
    readln (tt,l)
  ...
  Closefile(tt);
  ...
  assignfile(tt,'text.txt');
  Append(tt); // This would set the position at the end of file.
  writeln(tt,'blablabla');
  ...
  Closefile(tt);
end;
Hope that helps.

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top