1
我正在写一个自定义的结构处理程序,我有以下几种类型:帕斯卡尔 - 神秘的领域增加
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
会很gladful,如果有人清除的情况对我来说。先谢谢你。
那么,我不读任何文件,输入读入结构的字段。 – Arnthor 2011-03-12 09:44:29
@Nordvind - 然而,你正在阅读的价值,这似乎是最合理的解释。测试很简单,将'13'换成'10',然后看看。顺便说一句,你跳过第一个元素,你想切换'Inc'和'Read'的位置。 – 2011-03-12 11:13:31
@Sertac Akyuz:我也认为'Read'应该放在'Inc'之前,但是后来我看到该数组被定义为char'的data:array [StrPos],并且不知道'StrPos'是否标识以0开头的索引范围,虽然OP有可能错误地将其替换为“StrLen”,它以0开始。 – 2011-03-12 12:37:38