jduarte@BONNIE.ICS.UCI.EDU (09/29/89)
Hello, I need some help on the topic of disk operations...and NO, this question has nothing to do with my homework !!! Is there any easy way in TP 5.0 to tell whether a disk file is CLOSED or OPEN...I mean, suppose that I write ASCII characters to a disk file and then the disk becomes full...I can check for an IO error using the IOresult system function, but sometimes, I try to write a message to the screen after detecting an IO error, and the TP integrated environment traps this writeln statement as an IO error....Even though I compiled using the directive {$I-} and after reading the IO status IOresult immediately after the disk write.... I tried closing the disk file immediately after I detected an IO error, but my system just hangs after the file is closed (reboot needed) or TP 5.0 reports that I am trying to close a closed file...Hmmmmmmmmmmmmmmmm. Any thoughts from the TP gurus will be appreciated, and please, NO snide remarks. Thanks, Jose Duarte University of California, Irvine jduarte@bonnie.ics.uci.edu
ts@chyde.uwasa.fi (Timo Salmi LASK) (09/29/89)
In article <8909281232.aa13997@BONNIE.ICS.UCI.EDU> jduarte@BONNIE.ICS.UCI.EDU writes: >has nothing to do with my homework !!! > Is there any easy way in TP 5.0 to tell whether a disk file is CLOSED >or OPEN...I mean, suppose that I write ASCII characters to a disk file and >then the disk becomes full...I can check for an IO error using the IOresult A very good question! I shall have to look more fully if I can come up with something positive. In the meanwhile there is one little trick, which does not solve the problem, but which is good practice anyway. You say that you test the IOResult. One is well adviced to do this *also* after each close statement, because there are rare cases of a near full disk, which may otherwise cause problems. There is also another small trick. I do not know if you have used it in your program. That is turning the io-checking back on *immediately* after each write. The structure then is like this: {$I-} writeln (f, 'My message on homework has been obviously heeded to :-)'); {$I+} if IOResult <> 0 then begin ... end; {$I-} writeln (f, 'If it is impractical, the authorities will go for it'); {$I+} if IOResult <> 0 then begin ... end; You you find it irksome doing this repetitively (I do) then make a procedure that performs a single write with IOResult checking. But what is really interesting is your question about testing for an open file. I do not recall seeing it done, but it certainly would be a useful function to have. ................................................................... Prof. Timo Salmi (Site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: vakk::salmi Bitnet: salmi@finfun
demon@thor.wright.edu (Brett Kottman) (09/30/89)
From article <8909281232.aa13997@BONNIE.ICS.UCI.EDU>, by jduarte@BONNIE.ICS.UCI.EDU: > Hello, > > I need some help on the topic of disk operations...and NO, this question > has nothing to do with my homework !!! > > Is there any easy way in TP 5.0 to tell whether a disk file is CLOSED > or OPEN...I mean, suppose that I write ASCII characters to a disk file and > then the disk becomes full...I can check for an IO error using the IOresult You can use TP's built in function to check on how much disk space is left before you do a write. In addition, you can keep track of whether a file is open by doing a check on the file type record. (pages 348-9 in the TP 4.0 manual) CONST fmClosed = $D7B0 (file is closed) fmInput = $D7B1 (file is text and reset) fmOutPt = $D7B2 (file is text and rewritten) fmInOut = $D7B3 (file is typed/untyped reset or rewritten == open file) These can be accessed in the mode field of the filevar record: current_status := filevar.mode and then checking it against the CONST values. Hope this helps. Brett Kottmann Wright State Univ. ================================================================================Committed to helping even those who's questions are releated to their homework and never obtaining a snobbish ivory tower attitude ================================================================================