Newsgroups: comp.lang.pascal Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!umich!sharkey!tygra!dave From: dave@tygra.Michigan.COM (David Conrad) Subject: Re: TP error while opening R/O files Organization: CAT-TALK Conferencing System, Detroit, MI Date: Thu, 9 May 91 10:00:31 GMT Message-ID: <1991May9.100031.25333@tygra.Michigan.COM> Keywords: r/o turbo pascal 6.0 borland files opening error References: <1991May02.160542.28060@cs.ruu.nl> <9144@mcshh.hanse.de> In article <9144@mcshh.hanse.de> frimp@mcshh.hanse.de (Frank Heinzius) writes: > >[In response to a question about accessing read only files] > >You must reassign the "filemode" system variable like this: > >temp := filemode; >filemode := 0; >reset(read_only_file); >{other file operations} >{...} >close(read_only_file); >filemode := temp; Incidentally, filemode need not be changed the whole time the read only file is opened, only while opening (i.e., resetting,) it. It is best to always open files you only intend to read with filemode set to 0, e.g. filemode := 0; (* open input file in read mode *) reset (infile); filemode := 2; (* open output file in read/write mode *) reset (outfile); while not eof(infile) do (* do it! *) close (infile); close (outfile); If you try to open a file with filemode = 2, even if you reset, not rewrite it, even if you only read from it, you will get a runtime error (access denied). DOS won't allow a read only file to be opened in read/write mode, and rightly so. (BTW, 2 is the default for filemode, so if you don't set it to anything, 2 (read/write) is what you get.) Even if you expect a file not to be read only, if you only want to read it, it's best to let the operating system know that. Why? Well, a user may mark a file which she knows is strictly an input file read only to prevent it getting clobbered. Do you want your application to crash then? Or perhaps your program gets loaded onto a network. A user might not have write priviledges in the current directory, which means that your program will crash even if the specific file isn't marked read only, because the network won't allow the current user to open *any* of the files in the current directory for writing. Also, for networks and file sharing, it's important that the network know just exactly how the file is to be used, but that is, as they say, beyond the scope of this article. Also I should mention that this article is mostly not a response to Frank's article, but just general info. David R. Conrad | "A dream unthreatened by the morning light dave@michigan.com | could blow this soul right through the roof ...!tygra!dave | of the night." -- Pink Floyd, "Learning to Fly" -- = CAT-TALK Conferencing Network, Computer Conferencing and File Archive = - 1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new' - = as a login id. AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET") = E-MAIL Address: dave@Michigan.COM