Analyzing TFileStream's Mode

Hello.

I'm making a DLL (especially for Delphi apps) which shall be used as an interface library to my app's data file type.

The read/load/decode functions do work well, but now id like to enahnce it with Write-Functions.

For a better understanding, thats how the basics of my DLL are done:

1. Call InitDBX
This is the Function which initializes my Engine. The Func takes parameters
FileName, 2 PTRs to Buffers and the FileStream-Mode, which is similar to the syntax of TFileSTream.Create.

Eg. that call could look like:
InitDBX('c:\test.dbx', HeaderBuf, SampleBuf, fmOpenRead or fmShareDenyWrite)

Now you could call functions to load dta from the the DBX-File, eg. LoadHeader. As you see, this FileMode would not allow writing to the DBX-File.

So if you do a call to WriteHeader (or anyother function to write data) i want to make sure that you have specified a FileMode which allows writing.

But thats my problem. Even if i save a copy of the FileStream-Mode in a gloval Value, i dunno how to analzy this Word-Value. How can I detect, that we got actually the Permission to write files ?

Regarding the Delphi Help on TFileStream.Create, at least one of the following Constants/Values musrt be included.
fmOpenReadWrite or fmWrite

How to find out if they are given ?

thx, Roger
LVL 2
omsecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
I'd recommend that you use a flag for the dbx file say "ReadOnly" which can be set during initialization by:

  ReadOnly := (ShareMode and (fmOpenReadWrite or fmWrite)) <> 0;

Ciao, Mike
0
philipleighsCommented:
To see if specific flags are supplied do this (just illustrating how to use bit fields):

WriteFlagIncluded := FileMode and fmWrite > 0;

Cheers,
Phil.
0
omsecAuthor Commented:
WriteFlagIncluded := FileMode and fmWrite > 0;

oh thats all ?

so WriteFlagIncluded := (FileMode and fmOpenWrite) or (FimeMode and fmOpenReadWrite) works too ?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

omsecAuthor Commented:
WriteFlagIncluded := (FileMode and fmOpenWrite > 0) or (FimeMode and fmOpenReadWrite > 0)

...i mean
0
philipleighsCommented:
That's the ticket!
0
philipleighsCommented:
Mike was in first though.
0
LischkeCommented:
Sometimes it is easier then one thought :-) (although, I suppose you already guessed that it would be so easy as the donated points indicate ;-^ )

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
omsecAuthor Commented:
erstaunlich :P
0
LischkeCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.