omsec
asked on
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
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
To see if specific flags are supplied do this (just illustrating how to use bit fields):
WriteFlagIncluded := FileMode and fmWrite > 0;
Cheers,
Phil.
WriteFlagIncluded := FileMode and fmWrite > 0;
Cheers,
Phil.
ASKER
WriteFlagIncluded := FileMode and fmWrite > 0;
oh thats all ?
so WriteFlagIncluded := (FileMode and fmOpenWrite) or (FimeMode and fmOpenReadWrite) works too ?
oh thats all ?
so WriteFlagIncluded := (FileMode and fmOpenWrite) or (FimeMode and fmOpenReadWrite) works too ?
ASKER
WriteFlagIncluded := (FileMode and fmOpenWrite > 0) or (FimeMode and fmOpenReadWrite > 0)
...i mean
...i mean
That's the ticket!
Mike was in first though.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
erstaunlich :P
:-)
ReadOnly := (ShareMode and (fmOpenReadWrite or fmWrite)) <> 0;
Ciao, Mike