我正在编写一个自定义结构操作程序,我有以下类型:
type
StrLen = 0..MaxLen;
Str = ^StrInst;
StrInst = record
length: StrLen;
data: array [StrPos] of char;
end;
然后我有以下程序:
procedure ReadStr(var S: Str);
var pos: StrLen;
begin
S^.length:=0;
pos := 0;
writeln('pos before entering:',pos);
writeln;
with S^ do begin
repeat
Inc(pos);
Read(data[pos]);
until (ord(data[pos]) = 13) or (pos > MaxLen+1);
writeln('pos after entering:',pos);
length := pos-1;
end;
end;
问题是,当我读入该类型的第二个对象时,pos变量以及长度字段神秘地增加了 1。以下代码
ReadStr(S1);
ReadStr(S2);
输出(当我在两种情况下输入“123”时):
pos before entering:0
123
pos after entering:4
pos before entering:0
123
pos after entering:5
如果有人为我清除情况,将非常高兴。先感谢您。