2016-02-03 96 views
1

当我运行这个程序帕斯卡尔unhandles出现异常

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; 

我得到的错误

未处理的异常发生在$ 00000000: EAccessViolation:访问冲突 $ 00000000 $ 2A005640 $ B6F83F97

不幸的是,我无法在互联网上找到解决方案,非常感谢帮助!

+2

我不知道你在使用什么Pascal编译器,但你应该打开任何激进的运行时检查,例如[数组范围检查](http://www.freepascal.org/docs- HTML/PROG/progsu65.html)。它会帮助你,直到你拥有你的海腿。而像这样的节目,表现的惩罚是不重要的。 – lurker

回答

1

你已经声明一个数组目录为1..100,但在第一次运行时将计数设置为0。目录[0]超出范围。你可能试图写只读内存。