Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: CBXE8 - FileOpen() with fmOpenRead | fmOpenWrite flags not working ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Aug 31, 2015 10:52 PM Last Post By: GAI CHEW KAI
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
CBXE8 - FileOpen() with fmOpenRead | fmOpenWrite flags not working ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 27, 2015 12:10 AM
Embarcadero® C++Builder XE8 Version 22.0.19027.8951, Indy 10.
Windows 10 Pro x64
Android 4.1.2

QUESTIONS

1. The instruction FileOpen() below resulted in FileRead() error, FileWrite() ok.

FileOpen( UnicodeString( p ), fmOpenRead | fmOpenWrite | fmShareDenyNone );

2. Later, I specified only fmOpenRead flag, the FileRead() ok.

FileOpen( UnicodeString( p ), fmOpenRead );

This results the use of two file handlers, why fmOpenRead | fmOpenWrite not working for both FileRead() and FileWrite() ?

Please advise.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: CBXE8 - FileOpen() with fmOpenRead | fmOpenWrite flags not working ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 27, 2015 9:19 AM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
GAI wrote:

1. The instruction FileOpen() below resulted in FileRead() error,
FileWrite() ok.

FileOpen( UnicodeString( p ), fmOpenRead | fmOpenWrite | fmShareDenyNone );

fmOpenRead is defined as 0, so it cannot be mixed with other open flags.
If you want to read and write, you need to use the fmOpenReadWrite flag
instead, which is defined as 2:

FileOpen( UnicodeString( p ), fmOpenReadWrite | fmShareDenyNone );


2. Later, I specified only fmOpenRead flag, the FileRead() ok.

FileOpen( UnicodeString( p ), fmOpenRead );

When fmOpenRead is used by itself like that, it opens the file for read-only
exclusive access.

why fmOpenRead | fmOpenWrite not working for both FileRead() and FileWrite()
?

Because fmOpenRead and fmOpenWrite are not designed to be used together.
You have to use fmOpenReadWrite instead.

--
Remy Lebeau (TeamB)
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Re: CBXE8 - FileOpen() with fmOpenRead | fmOpenWrite flags not working ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2015 10:52 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Working now. Thanks again Remy.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02