Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush a TFileStream?

TFileStream provides buffered output, which is great in most cases, but in some cases (especially during debugging) it's nice to flush the buffer immediately. Thing is, I don't know of any way to do that except calling Free, which is kind of counterproductive.

Is there a better way to do it?

like image 765
Mason Wheeler Avatar asked Apr 24 '09 18:04

Mason Wheeler


2 Answers

You need to flush the stream. Try:

 FlushFileBuffers(fs.Handle); 

? Did you see/try this?

like image 186
cgp Avatar answered Oct 09 '22 12:10

cgp


I think altCognito's answer (FlushFileBuffers) is probably the best, but only because TFileStream does no buffering by itself. For other, buffered, streams should first look if the stream offers a Flush method. And as a last resort you could probably use the old trick of Seek(Begin) and then Seek(CurrentPos).

like image 43
Henk Holterman Avatar answered Oct 09 '22 12:10

Henk Holterman