皮格马利翁效应的应用:只读文件是否可以用reset打开?

来源:百度文库 编辑:中科新闻网 时间:2024/04/30 11:04:43
我用delphi打开只读文件时,使用reset,结果程序出了异常。编程时怎样才能打开只读文件

In Delphi code, Reset opens the existing external file with the name assigned to F using the mode specified by the global FileMode variable. An error results if no existing external file of the given name exists or if the file can抰 be opened with the current file mode. If F is already open, it is first closed and then reopened. The current file position is set to the beginning of the file.

Warning: The default value of FileMode is 2 (Read/Write access). If this is not changed to a read-only file mode before calling Reset, attempts to open read-only files will fail.

F is a variable of any file type associated with an external file using AssignFile. RecSize is an optional expression, which can be specified only if F is an untyped file. If F is an untyped file, RecSize specifies the record size to be used in data transfers. If RecSize is omitted, a default record size of 128 bytes is assumed.

If F is assigned an empty name, such as AssignFile(F, ''), then after the call to Reset, F refers to the standard input file.

If F is a text file, F becomes read-only.

After a call to Reset, Eof(F) is true if the file is empty; otherwise, Eof(F) is false.
如果文件只读就会打开失败,所以你可以用其它的函数
比如fileopen
function FileOpen(const FileName: string; Mode: LongWord): Integer;
Mode On Windows:

const

fmCreate = $FFFF;
fmOpenRead = $0000;
fmOpenWrite = $0001;
fmOpenReadWrite = $0002;

fmShareCompat = $0000 platform;
fmShareExclusive = $0010;
fmShareDenyWrite = $0020;
fmShareDenyRead = $0030 platform;
fmShareDenyNone = $0040;