Solved

TFileStream "append" mode?

Posted on 2002-04-22
3
2,816 Views
Last Modified: 2012-06-21
Hi...
  In my app I've created a disk file with TFileStream in "create" mode. I wish to close this FileStream, then re-open it later in my app and append more data to it. How do I do that? I don't see an "append" mode for TFileStream.

Thanks
  Shawn
0
Comment
Question by:aztec
3 Comments
 
LVL 2

Accepted Solution

by:
Kalroth earned 50 total points
ID: 6961132
I hope this answers your problem.

-- CODE SNIPPIT --

var
  myFile : String;
  yourFile : TFileStream;

begin
  myFile := 'asillyfilename.txt';
  if FileExists(myFile) then begin
    yourFile := TFileStream.Create(myFile,fmOpenReadWrite);
    yourFile.Seek(0,soFromEnd);
  end else begin
    yourFile := TFileStream.Create(myFile,fmCreate);  
  end;

 .. code here ..

end;

-- CODE SNIPPIT --
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6972857
This one would have the same effect:

  with TFileStream.Create('anothersillyfilename.txt', fmOpenReadWrite) do
    try
      Seek(0, soFromEnd);
      .. code here ..
    finally Free end;

If the file does not exist, it is automatically created. So no need to check for the existance of the file.

Regards, Madshi.
0
 

Author Comment

by:aztec
ID: 6975354
thanks
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question