我定义了一个动态数组 stExam:array of ^Exam;Exam 的结构是这样的:Exam=record
cStuID: array[0..11] of ansichar;
fScore:single;
BAnswer:array[0..163] of Byte;
fUnit:array[0..163] of single;
end;动态分配了十个空间给stExam
SetLength(stExam,10);
for i:=0 to 9 do
begin
new(stExam[i]); end;
然后读文件的数据.DATNumRead:=1;
Reset(bFile,1);
BlockRead(bFile,stExam,sizeof(Exam)*10,NumRead);///这里出错 EinoutError IO998 当我把stExam改为静态结构体数组时,一样的代码,它就没有错误了,数据能够正确读出。
郁闷很久,不知何故,愿高人指教
cStuID: array[0..11] of ansichar;
fScore:single;
BAnswer:array[0..163] of Byte;
fUnit:array[0..163] of single;
end;动态分配了十个空间给stExam
SetLength(stExam,10);
for i:=0 to 9 do
begin
new(stExam[i]); end;
然后读文件的数据.DATNumRead:=1;
Reset(bFile,1);
BlockRead(bFile,stExam,sizeof(Exam)*10,NumRead);///这里出错 EinoutError IO998 当我把stExam改为静态结构体数组时,一样的代码,它就没有错误了,数据能够正确读出。
郁闷很久,不知何故,愿高人指教
或者将stExam定义为array[0..MAXINT]of Exam;
然后对stExam使用GetMem等进行内存分配(释放时配对)也可以,并且是比较建议的.
type
Exam = record
cStuID: array[0..11] of ansichar;
fScore:single;
BAnswer:array[0..163] of Byte;
fUnit:array[0..163] of single;
end; PExamList = ^TExamList;
TExamList = array[0..Maxint div 16 - 1] of Exam;
...
var
stExam: PExamList;
...