![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
sharing violation
TUser © (2004-11-04 14:34:00)Почему, если файл открыт, как rewrite(filevar) и программа туда чего-то пишет, то его можно при этом открыть в другой программе для чтения. А если пишем через TFileStream - то при попытке открыть его (в FAR'е, например) - получаем ошибку? Типа - файл занят.
VMcL (2004-11-04 15:29:00) [1]>> TUser © (04.11.04 15:02) [2]
> Когда через стрим - то стоит fmOpenWrite, никакого fmShareDeny... нет, т.е. вроде бы файл д.б. доступен в других программах (по крайней мере для чтения) - ан нет.
Никому он ничего не должен :-)
Тогда срабатывает fmShareCompat = $0000. Ставь явно fmShareDenyNone или fmShareDenyWrite (см. [3]).
VMcL (2004-11-04 15:24:00) [2]>> TUser © (04.11.04 14:34)
TFileStream.Create(..., fmCreate) открывает в монопольном режиме. См. исходники VCL.
Rem (2004-11-04 15:08:00) [3]File open mode constants
File open mode constants are used to control the access mode to a file or stream.
Unit
SysUtils
Category
file management routines
const
fmOpenRead = $0000;
fmOpenWrite = $0001;
fmOpenReadWrite = $0002;
fmShareCompat = $0000;
fmShareExclusive = $0010;
fmShareDenyWrite = $0020;
fmShareDenyRead = $0030;
fmShareDenyNone = $0040;
Description
The file open mode constants are used when a file or stream is opened to control how it can be shared.
The TFileStream constructor has a Mode parameter that you can set to one of these constants:
Constant Definition
fmCreate If the file exists, open for write access,
otherwise, create a new file.
Unlike the other constants, which are declared
in the SysUtils unit, this constant is
declared in classes.pas.
fmOpenRead Open for read access only.
fmOpenWrite Open for write access only.
fmOpenReadWrite Open for read and write access.
fmShareCompat Compatible with the way FCBs are opened.
fmShareExclusive Read and write access is denied.
fmShareDenyWrite Write access is denied.
fmShareDenyRead Read access is denied.
fmShareDenyNone Allows full access for others.
TUser (2004-11-04 15:02:00) [4]FileMode (судя по справке) влияеть не Reset. Я открывал Rewrite'ом.
Когда через стрим - то стоит fmOpenWrite, никакого fmShareDeny... нет, т.е. вроде бы файл д.б. доступен в других программах (по крайней мере для чтения) - ан нет.
panov (2004-11-04 14:40:00) [5]TUser © (04.11.04 14:34)
Смотря в каком режиме открываешь файл. см. глоб. переменную FileMode