Solved

TFileStream "append" mode?

Posted on 2002-04-22
3
2,849 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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