Archived

This topic is now archived and is closed to further replies.

Strange problem when reading from files

This topic is 5005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is a file parser that reads numbers out of a textfile. It works fine, but only the first time it is called. When I call this routine again with another filename, it generates an "I/O error 6" as soon as "Readln" is executed.
procedure LesePPD(Filename: PChar);
var
  datei: TextFile;
  Zeile: array[0..255] of Char;
  strXZahl: string;
  strYZahl: string;
  strZZahl: string;
  StartPos, EndPos: DWORD;
  i, n: DWORD;
begin
  DecimalSeparator := ''.'';

  AssignFile(datei, Filename);
  Reset(datei);

  repeat
    Readln (datei, zeile);
    if (Eof(datei)) then begin
      MessageBox(0, ''Fehler beim Lesen von PPD'', ''Fehler'', MB_OK);
      Exit;
    end;
    StartPos := PosEx(''Vertices: '', zeile, 1);
  until (StartPos > 0);

  StartPos := StartPos + 10;
  EndPos := PosEx('' '', zeile, StartPos);
  g_dwTempNumVertices := StrToInt(MidStr(zeile, StartPos, (EndPos - StartPos)));

  g_vTempPPDArray := nil;
  SetLength(g_vTempPPDArray, g_dwTempNumVertices);

  i := 0;
  Readln (datei, zeile);
  Readln (datei, zeile);
  while (LeftStr(zeile, 7) = ''Vertex '') do begin
    if (i >= g_dwTempNumVertices) then begin
      MessageBox(0, ''Fehler beim Lesen von PPD'', ''Fehler'', MB_OK);
      Exit;
    end;

    StartPos := PosEx(''X:'', zeile, 10) + 2;
    EndPos := PosEx('' '', zeile, (StartPos + 1));
    strXZahl := MidStr(zeile, StartPos, (EndPos - StartPos));

    StartPos := PosEx(''Y:'', zeile, 10) + 2;
    EndPos := PosEx('' '', zeile, (StartPos + 1));
    strYZahl := MidStr(zeile, StartPos, (EndPos - StartPos));

    StartPos := PosEx(''Z:'', zeile, 10) + 2;
    strZZahl := MidStr(zeile, StartPos, Length(zeile));

    g_vTempPPDArray[i].x := StrToFloat(strXZahl);
    g_vTempPPDArray[i].z := StrToFloat(strYZahl);
    g_vTempPPDArray[i].y := StrToFloat(strZZahl);

    i := i + 1;

    Readln (datei, zeile);
  end;

  CloseFile(datei);

end;

Share this post


Link to post
Share on other sites
is it possible that it is just the second file that has an error in it? you might try reversing the order of the reads, and see if it still errors out on the second call.

google said Borland had this to say:

Runtime error 6 is defined in the online help as:



106 Invalid numeric format Reported by Read or Readln if a numeric value read from a text file does not conform to the proper numeric format.



lonesock

Piranha are people too.

Share this post


Link to post
Share on other sites
When I change the order of the calls, it still generates an exception the second time it is called. Has nothing to do with the files.

Share this post


Link to post
Share on other sites