Jump to content
Sign in to follow this  
hsauro

TFileStream with TStreamReader question

Recommended Posts

What is the advantage of using TFileStream with TStreamReader compared passing the filename directly to TStreamReader?

 

For example, what is the difference between these two:

 

    f = TStreamReader.Create (fileName)

 

or

 

    f = TStreamReader.Create (TFileStream.Create (fileName, fmOpenRead))

Share this post


Link to post

TStreamReader.Create (fileName) passes the flags as:

 

fmOpenRead or fmShareDenyWrite

 

Sadly, none of the overloads allow you to change this. Worse still: its counterpart TStreamWriter.Create can fail on platforms other than iOS because the flags don't include fmShareDenyWrite

Edited by Dave Nottage
  • Like 1

Share this post


Link to post

Thanks for that. So it's better to use f = TStreamReader.Create (TFileStream.Create (fileName, fmOpenRead)) because one has more control over the flags.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×