Solved

TFileStream "append" mode?

Posted on 2002-04-22
3
2,760 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now