Delphi XE3 gives EFOpenError when specifying "FILE_SHARE_READ or FILE_SHARE_WRITE" in TFileStream's constructor

StackOverflow https://stackoverflow.com/questions/14424904

  •  16-01-2022
  •  | 
  •  

Question

Following statement runs fine under Delphi XE (Windows 7 x64) but gives "Exception class EFOpenError with message..." under Delphi XE3 (Windows 7 x64). It looks like a bug. If so, is there a workaround?

      TFileStream.Create(
        'C:\Test.txt'
        , fmOpenRead,
//        FILE_SHARE_READ);
//        FILE_SHARE_WRITE);
        FILE_SHARE_READ or FILE_SHARE_WRITE);
Was it helpful?

Solution

Use fmShareDenyNone constant instead of FILE_SHARE_READ or FILE_SHARE_WRITE:

 TFileStream.Create(
    'C:\Test.txt', fmOpenRead or fmShareDenyNone);

it is not a bug. See Documentation for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top