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 <[email protected]> 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 <[email protected]>: >> 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 > [email protected] > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > _______________________________________________ Lazarus mailing list [email protected] http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
