• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3089
  • Last Modified:

TFileStream "append" mode?

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
aztec
Asked:
aztec
1 Solution
 
KalrothCommented:
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
 
MadshiCommented:
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
 
aztecAuthor Commented:
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now