FmShareDenyWrite mode not working

I am using TFileSteam to open a log file. I would like to be able to read this log file from other processes. I thought fmShareDenyWrite mode would allow this.

However, if I try to open the file from other processes, I get an error message. For example, if I try to enter a file from the command line, I get "the process cannot access the file because it is being used by another process."

Here is the file initialization code:

if FileExists(AutoLogFileName) then
   _ActivityLogStream := TFileStream.Create(AutoLogFileName, 
          fmOpenReadWrite or fmShareDenyWrite)
else
   _ActivityLogStream := TFileStream.Create(AutoLogFileName, 
          fmCreate or fmShareDenyWrite);

Note: I am using Delphi version 6.

+5
source share
2 answers

, ​​D6, . , D2007: QC 65767: http://qc.embarcadero.com/wc/qcmain.aspx?d=65767. , D2010 (, 14.0.3467.22472).

( Gabr):

TFileStream, . Create(const AFileName: string; Mode: Word; Rights: Cardinal) ( ) .

  if Mode = fmCreate then
  begin
    inherited Create(FileCreate(AFileName, Rights));

  if (Mode and fmCreate = fmCreate) then
  begin
    myMode := Mode and $FF;
    if myMode = $FF then
      myMode := fmShareExclusive;
    inherited Create(FileCreate(AFileName, myMode, Rights));

myMode var Word.

+8

mfCreate share. ,

+2

All Articles