Agent1229
Agent1229

Reputation: 11

Pascal unhandles exception occured

When I run this procedure

procedure displaydir;
var count:integer;
    directoryfile: file of tdir;
    directory:array [1..100] of tdir;

begin
     assignfile(directoryfile, 'directory.bin');
     reset(directoryfile);
     count:=0;
     repeat
     read(directoryfile,directory[count]);
     writeln('Name: ',directory[count].name);
     writeln('Telephone number: ',directory[count].tel);
     writeln('Job title: ',directory[count].jobtitle);
     writeln;
     writeln;
     count:=count+1;
     until (directory[count-1].name = 'q');


end;

I get the error

An unhandled exception occurred at $00000000: EAccessViolation: Access violation $00000000 $2A005640 $B6F83F97

Unfortunately I couldn't find a solution on the internet, help is much appreciated!

Upvotes: 1

Views: 696

Answers (1)

Rob11311
Rob11311

Reputation: 1416

You've declared an array directory as 1..100, but set count to 0 on first run through. directory[ 0] is out of range. You're probably trying to write to read only memory.

Upvotes: 1

Related Questions