2016-02-03 150 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]超出範圍。你可能試圖寫只讀內存。