Saving a TFileStream

I am using a TFileStream, is there anyway to save the stream apart from uing free. I am opening the stream
    oStream := TFileStream.Create( sFilename, fmShareExclusive or fmOpenReadWrite );

I keep the file open so no one else can open it, the user needs to be able to click save at any time and I need to save all changes up to that point.

LVL 3
julianpointerAsked:
Who is Participating?
 
Wim ten BrinkSelf-employed developerCommented:
Well, when you write to the stream, it should be written to disk immediately. That's basic behaviour for filestreams... By using free, you also force the buffers to be written.  But in general these buffers are handled by Windows, not by the stream itself. You could try:

  FlushFileBuffers(oStream.Handle);

just in case...
0
 
wolsenCommented:
you could just create another file stream and copy that stream to it.
0
 
Lukasz LachCommented:
or you can use LockFile() function to protect the file from being written (or read) by other process...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.