I am getting a value returned from ioresult, of 0. Which is an (apparently) undocumented value. Here is the relevant code:
procedure GetNextSourceLine();
{ *** GETNEXTSOURCELINE
*** Identify the current SourceFile in the SourceFileTable
*** This is given by the global variable CurrentSource. The entry
*** in SourceFileTable will include not only the handle for the file,
*** but also the important information about the file that will make
*** it possible to know how to read the next line. See tSFTEntry=record }
var
SourceFile : THandle;
inputline : string[MAXSOURCELINELENGTH]; {=120}
outputline : string;
ReadLength : integer;
ReadError : integer;
msg : string;
begin
with SourceFileTable[CurrentSource] do
begin
SourceFile := SFTFile;
ReadError := 0;
{$i-}
if CurrentSource = 1 then
begin
ReadLength := FileRead
(SourceFile, inputline, MAXSOURCELINELENGTH);
end
else
begin
ReadLength := FileRead
(SourceFile, inputline, MAXSOURCELINELENGTH);
end;
ReadError :=ioresult();
{$i+}
if ReadLength = -1 then
begin
msg := 'Error in FileRead: ' + format('%-10d',[ReadError]);
write(msg);
readln()
end
else
begin
SFTLastLineNum := SFTLastLineNum + 1;
SourceLineNum := SFTLastLineNum;
SFTLastLinePos := 0;
SFTRecNum := SFTRecNum + 1;
SFTLastSourceLine := inputline;
end;
end;
(The distinction between CurrentSource = 1 and CurrentSource = any other value is a 'future consideration').
When I step through the code, I take the first path through the if statement, and get the (un) expected value of -1 in the ReadLength variable. Then, when I try to capture the error code (from ioresult) the returned value is 0.
So now I have a situation where FileRead says "Oops, there's an error here (but I'm not going to tell you what)", and ioresult says "Nothing wrong here - why are you troubling me?"
Notes:
I do not have an explicit uses for the System unit (when I add it I get an error message "Duplicate Identifier" even though it's nowhere to be found)
The examples for FileRead etc all indicate that if an error is detected -1 is returned. The only example of actually testing for this that I found included the fun code:
F:= Fi leCreate ( ' t e s t . dat ' ) ;
I f F = -1 then
Halt ( 1 ) ;
which seems more than slightly extreme!
Is it, perhaps, the case that when using the alternate routines (FileOpen, FileClose, etc) the only help you get is a terse Error, and that's it? Or is it the case that ioresult() does not apply to these routines (in which case, what does?) or something else?
Is there a way to find out what error condition resulted in a return code of -1? Or do we simply keep trying /beating our head against a brick wall / or something else?
(Incidentally, my confidence in documentation which describes all of these routines as functions and then conveniently omits to test any return value, is vanishingly close to zero).
Frustrated as usual, sorry for the polemics, any and all suggestions appreciated!
Tony
Turned out I had dropped a character in a filename which I had carefully stored (with the dropped character) in a comment in the source, so that I wouldn't make mistakes typing it in! Too smart for my own good.
