我尝试运行以下代码,但它显示有关内存地址的错误,并显示一条消息“循环后 n 可能未定义”。请看一看。
var n_max : integer;
n: integer;
r, R1, f, h0 : Array of Real;
const
h = 0.00889; nip= 100;
cod = 10;
rod = 76;
nip_dia = 5; viscosity = 0.001; velocity = 76;
begin
n_max := Round(((rod-cod)/2)/h);
for n := 0 to n_max-1 do;
r[n]:= cod/2 + h*n;
R1[n] := (r[n]*(nip_dia)/2)/(r[n]+(nip_dia)/2);
f[n] := nip*((r[n]-r[0])/r[n]);
h0[n] :=4*viscosity*velocity*(1/(60*(R1[n]/f[n])));
WriteLn(r[n]);
WriteLn(R1[n]);
WriteLn(f[n]);
WriteLn(h0[n]);
ReadLn;
end.
您不为数组分配任何内存。您需要致电SetLength
要做到这一点。
SetLength(r, n_max);
// and likewise for the other arrays
更重要的是,循环什么也不做。该循环包含一条语句,该语句是一个空语句,以分号结尾do
.
for n := 0 to n_max-1 do;
// yes, that semi-colon is the end of the loop
你需要一个begin
/end
block.
for n := 0 to n_max-1 do
begin
// loop body goes in here
....
end;
// at this point, outside the loop, the value of n is ill-defined.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)