Why do the System.IOUtils functions and TStreamReader use fmShareCompat?

萝らか妹 提交于 2020-01-02 03:50:29

问题


When I first saw the System.IOUtils unit with functions like TFile.ReadAllBytes and TFile.ReadAllText and the TStreamReader and TBinaryReader classes in System.Classes I was quite excited to have easy ways to read binary and text files.

After using them for a while I noticed that the default share mode is implicitly fmShareCompat, since they all use TFileStream.Create, but do not explicitly specify a share mode.

Since fmShareCompat is treated as fmShareExclusive on Windows this leads to file locking problems when using them.

Is this an oversight by the Delphi developers? Or is there a reason to not use fmShareDenyWrite by default?

Also why is there no way to specify a share mode?

I am now tempted to write my own version of these classes in order to make them more sharing friendly.

来源:https://stackoverflow.com/questions/23359813/why-do-the-system-ioutils-functions-and-tstreamreader-use-fmsharecompat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!