Editors IDEs
--
Questions
--
Followers
Top Experts
is there a way in Delphi of appending a TStringList to a text file. SaveToFile only overwrites the file but doesnt append to the end of the file.
Thank you
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
var
 myFile : TextFile;
 text  : string;
begin
 // Try to open the Test.txt file for writing to
 AssignFile(myFile, 'Test.txt');
 ReWrite(myFile);
 // Write a couple of well known words to this file
 WriteLn(myFile, 'Hello');
 WriteLn(myFile, 'World');
 // Close the file
 CloseFile(myFile);
 // Reopen to append a final line to the file
 Append(myFile);
 // Write this final line
 WriteLn(myFile, 'Final line added');
 // Close the file
 CloseFile(myFile);
 // Reopen the file for reading
 Reset(myFile);
 // Display the file contents
 while not Eof(myFile) do
 begin
  ReadLn(myFile, text);
  ShowMessage(text);
 end;
 // Close the file for the last time
 CloseFile(myFile);
end;
var sl : TStringList;
Begin
sl := TStringList.Create;
if FileExists(FileName) then
sl.LoadFromFile(FileName);
sl.AddStrings(OtherStringList);
sl.SaveToFile(FileName);
sl.free;
end;
plus you don't provide resource protection. if file exists but you have no rights to read it or write to it, you will hvae an error on that line which will have as a side effect a memory leak :)
otehr than that it's an interesting solution.
this post is only meant as educational :)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Editors IDEs
--
Questions
--
Followers
Top Experts
Development in most programming languages is frequently done with an editor or integrated development environment (IDE). An IDE is a software application that provide comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. XCode, Visual Studio, Adobe Dreamweaver and Eclipse are some of the more popular development tools, but an editor or IDE can be anything from simple text editors to sophisticated programs. Related topics: All programming and development language, database and web based content management systems topics