【发布时间】:2018-05-29 06:12:02
【问题描述】:
我目前遇到了这些错误的问题,似乎无法解决它们,我已将错误和代码附在下面,谢谢。
错误:
适用于 i386 的免费 Pascal 编译器版本 2.6.4 [2014/02/26] 版权所有 (c) 1993-2014 by Florian Klaempfl 和其他人 目标操作系统:i386 的 Darwin 编译 BasicReadWrite.pas BasicReadWrite.pas(22,30) 错误: 不兼容的类型:得到“personArray”预期“LongInt” BasicReadWrite.pas(25,8) 错误:没有可用的默认属性 BasicReadWrite.pas(25,8) 致命:语法错误,“;”预期但“[” 发现致命:编译中止错误:/usr/local/bin/ppc386 返回 错误退出代码(如果您没有指定源文件是正常的 编译)
program BasicReadWrite;
type
Person = record
name: String;
age: String; // Should this be an integer? Why/Why not?
end;
personArray = array of Person;
procedure WriteLinesToFile(var myFile: TextFile; const pe: Person);
begin
WriteLn(myFile, pe.age);
WriteLn(myFile, pe.name);
end;
procedure PrintRecords(const ArrayOfPersons: personArray; count: Integer);
var
p: Person;
begin
setLength(p, ArrayOfPersons);
for count:= 0 to high(ArrayOfPersons) do
begin
p[count] := WriteLinesToFile();
end;
end;
procedure ReadLinesFromFile(var myFile: TextFile);
var
p: Person;
number: Integer;
ArrayOfPersons: personArray;
begin
for number:= 0 to 20 do
begin
PrintRecords([number]);
end;
end;
procedure Main();
var
myFile: TextFile;
begin
AssignFile(myFile, 'mytestfile.dat');
ReWrite(myFile); // Use ReWrite to open a file for writing
WriteLinesToFile(myFile);
Close(myFile); // We need to close the file and re-open it, as Pascal
// will not let you Read and write from a file at the same time.
AssignFile(myFile, 'mytestfile.dat');
Reset(myFile); // Open the file for reading.
ReadLinesFromFile(myFile);
Close(myFile);
end;
begin
Main();
end.
【问题讨论】:
-
您的代码有很多错误。您使用了错误的类型、错误的语法、传递的参数并不总是与声明的参数匹配等。编译器对此无能为力。例如。在 ReadLinesFromFile 中,您不会从文件中读取任何内容。在 PrintRecords 中,您实际上也不打印记录,并且使用了错误的类型,向 SetLength 传递了错误的参数,完全不清楚为什么要使用数组。给人的印象是你并不真正知道自己在做什么。请教老师或导师或任何人来帮助你。
标签: pascal