[Lazarus] Appending to a binary file

Andrew Brunner andrew.t.brunner at gmail.com
Thu Jan 8 21:20:22 CET 2009


Yes,  if you've got a bunch of operations into this method write a
wrapper class this way you can keep the stream alive until such time
as it's not needed.  Using FS.Seek(0 sofromEnd) or whatever you need
to position the Stream.

On Thu, Jan 8, 2009 at 1:55 PM, Dave Coventry <dgcoventry at gmail.com> wrote:
> Andrew (or anyone else), in the example you provided below, you
> instantiate the Filestream:
>
> FS:=TFileStream.Create(sFileName, fmshareDenyWrite);
>
> after which you use a try...finally block to write data to the file
>
>  Try
>    FS.Seek(0,soFromEnd);
>    FS.WriteBuffer(sBuffer[1],iLength);
>  Finally
>    FreeAndNil(FS):
>  end;
>
> My question is: Does the FreeAndNil line free the stream? If I want to
> write again to the file, don't I need to instantiate the FS
> TFileStream object again using TFileStream.Create?
>
> 2008/12/19 Andrew Brunner <andrew.t.brunner at gmail.com>:
>> procedure Append();
>> var
>>  sBuffer:string;
>>  iLength:integer;
>> begin
>>
>>  sBuffer:='My Appended String'#13#10;
>>  iLength:=Length(sBuffer);
>>
>>  FS:=TFileStream.Create(sFileName, fmshareDenyWrite);
>>  Try
>>    FS.Seek(0,soFromEnd);
>>    FS.WriteBuffer(sBuffer[1],iLength);
>>  Finally
>>    FreeAndNil(FS):
>>  end;
>> end;
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>



More information about the Lazarus mailing list