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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
LischkeConnect With a Mentor Commented:
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
omsecAuthor Commented:
WriteFlagIncluded := FileMode and fmWrite > 0;

oh thats all ?

so WriteFlagIncluded := (FileMode and fmOpenWrite) or (FimeMode and fmOpenReadWrite) works too ?
0
 
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
 
omsecAuthor Commented:
erstaunlich :P
0
 
LischkeCommented:
:-)
0
All Courses

From novice to tech pro — start learning today.