Aidan Quinn
Aidan Quinn

Reputation: 1188

Debugger exception notification error for reading txt files in DELPHI

Im getting an error I haven't seen before.

Here's my code:

procedure TfrmPatientViewer.FormCreate(Sender: TObject);
var
  MyArray : array [1..100] of string;
  iCount : Integer;
  Patients : TextFile;
begin
  AssignFile(Patients, 'patients.txt');
  if FileExists('patients.txt') <> True
    then
      begin
        ShowMessage('Patients.txt does not exist, program shutting down');
        Application.Terminate;
      end;
  iCount := 1;
  while not Eof(Patients) do // <-- HERE'S THE ERROR
    begin
      Readln (Patients, MyArray[iCount]);
      redtOut.Lines.Add(MyArray[iCount]);
      inc(iCount);
    end;
end;

The error says: Project Phase3P.exe has raised an exception class ElnOutError with message 'I/O error 104'. Proccess stopped.

Why is it doing this and what can I do to make it work properly? I have searched around an can only find stuff on different I/O errors, but not this 104 one.

Upvotes: 2

Views: 737

Answers (2)

Teun Pronk
Teun Pronk

Reputation: 1399

Suggested edit for error.

procedure TfrmPatientViewer.FormCreate(Sender: TObject);
var
  MyArray : array [1..100] of string;
  iCount : Integer;
  Patients : TextFile;
begin
  try
    AssignFile(Patients,'patients2.txt');
    reset(Patients);
    iCount := 1;
    while not Eof(Patients) do // <-- HERE'S THE ERROR
      begin
        Readln (Patients, MyArray[iCount]);
        redtOut.Lines.Add(MyArray[iCount]);
        inc(iCount);
      end;
  except
    on E: EInOutError do
    begin
      raise Exception.Create('Patients.txt does not exist, program shutting down');
      Application.Terminate;
    end;
  end;
end;

This way you don't have to check the FileExists and it will raise your exception if its not found.
The one downside is that only the exception of EInOutError will raise the message.

Upvotes: 1

Aidan Quinn
Aidan Quinn

Reputation: 1188

Okay, I found my error after proof reading for the 4th time xD

I didn't put the reset(patients) after assigning the text file.

Upvotes: 1

Related Questions