我尝试运行以下代码,但它显示有关内存地址的错误,并显示一条消息,该消息在循环后可能未定义'。请看看。
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.
答案 0 :(得分:2)
您没有为阵列分配任何内存。您需要致电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
块。
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.