Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:53:05+00:00 2026-05-27T14:53:05+00:00

I’m using old style Pascal I/O routines and expect that calls to I/O functions

  • 0

I’m using old style Pascal I/O routines and expect that calls to I/O functions that fail should raise an EInOutError. When I try this I do not see an exception raised and I have no clue why.

procedure TForm1.Button1Click(Sender: TObject);
//var i: integer;
begin
id:=(strtoint(Edit1.Text)-1)*4;

AssignFile(plik,'\klienci\'+linia_klient[id]+'.txt');
try
Reset(plik);
except
  on EInOutError do Rewrite(plik);
  end;
edit2.Text:=linia_klient[id+1];
edit3.Text:=linia_klient[id+2];
//ListBox1.Clear;
//ListBox1.Items.Add();
end;

Entire code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label2: TLabel;
    Label3: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    ListBox1: TListBox;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  plik:TextFile;
  linia_klient,linia_video:array[0..20] of string;
  id:integer;

implementation

{$R *.dfm}
{$IOCHECKS ON}
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
Edit1.Text:='Witaj, Podaj ID klienta';
Label1.Caption:='ID';
AssignFile(plik,'klienci.txt');
Reset(plik);
i:=0;
While Not Eof(plik) do
  begin
    Readln(plik,linia_klient[i]);
    inc(i);
  end;

CloseFile(plik);
AssignFile(plik,'video.txt');
Reset(plik);
i:=0;
While Not Eof(plik) do
  begin
    Readln(plik,linia_video[i]);
    inc(i);
  end;

CloseFile(plik);
end;

procedure TForm1.Button1Click(Sender: TObject);
//var i: integer;
begin
id:=(strtoint(Edit1.Text)-1)*4;

AssignFile(plik,'\klienci\'+linia_klient[id]+'.txt');
try
Reset(plik);
except
  on EInOutError do Rewrite(plik);
  end;
edit2.Text:=linia_klient[id+1];
edit3.Text:=linia_klient[id+2];
//ListBox1.Clear;
//ListBox1.Items.Add();
end;

end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:53:06+00:00Added an answer on May 27, 2026 at 2:53 pm

    The exception EInOutError will only be raised if I/O checking is enabled. To make sure it is enabled do the following:

    • In your project options, in “Delphi Compiler Options” check the checkbox I/O checking
    • Remove any {$IOCHECKS OFF} or {$I-} directives from your code as they disable I/O checking

    This should give you a proper exception if the file doesn’t exist.

    Now if (for whatever reason) you cannot enable I/O checking:

    With disabled I/O checking you won’t get an EInOutError if something goes wrong. Instead you have to check the value of IOResult after every I/O operation. It’s like in old Pascal times: If IOResult <> 0 then an error happened.
    This (slightly adapted) excerpt from the Delphi docs shows how to work with IOResult:

      AssignFile(F, FileName);
      {$I-}
      Reset(F);
      {$I+}
      if IOResult = 0 then
      begin
        MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
          mtInformation, [mbOk], 0);
        CloseFile(F);
      end
      else
        MessageDlg('File access error', mtWarning, [mbOk], 0);
    

    However, nowadays you should use TFileStream to access/create files and don’t use the old style Pascal routines anymore. An example how this could look:

    filename := '\klienci\'+linia_klient[id]+'.txt';
    if not FileExists(filename) then
      // "Create a file with the given name. If a file with the given name exists, open the file in write mode."
      fs := TFileStream.Create(filename, fmCreate) else
      // "Open the file to modify the current contents rather than replace them."
      fs := TFileStream.Create(filename, fmOpenReadWrite);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.