我想用r的元素填充最后三个Edit。不知何故,i的价值并没有改变。请看看!
procedure TForm1.Button1Click(Sender: TObject);
var
r: Array of Real;
cod,h,N,code,i: Integer;
value: Real;
begin
Val(Edit1.Text, cod, code);
Val(Edit2.Text, h, code);
Val(Edit3.Text, N, code);
Edit1.Text := Edit1.Text;
Edit2.Text := Edit2.Text;
Edit3.Text := Edit3.Text;
setlength(r, N);
i:= 0;
while i<= N do
begin
r[i] := cod/2 + h*i;
i := i + 1;
end;
Edit4.Text := formatfloat('#.0', r[0]);
Edit5.Text := formatfloat('#.0', r[1]);
Edit6.Text := formatfloat('#.0', r[2]);
end;
end.
答案 0 :(得分:2)
您的代码包含许多无用且错误的代码。因此,我将从给定的信息中解决它。我在所有本地变量
中添加了前缀L
procedure TForm1.Button1Click(Sender: TObject);
var
Lr : Array[0..2] of Real;
Lcod, Lh : Integer;
LIdx : Integer;
begin
// throws an exception if Edit1.Text cannot converted to an Integer
Lcod := StrToInt( Edit1.Text );
// throws an exception if Edit2.Text cannot converted to an Integer
Lh := StrToInt( Edit2.Text );
for LIdx := 0 to 2 do
Lr[LIdx] := Lcod/2 + Lh*LIdx;
Edit4.Text := FormatFloat( '#.0', Lr[0] );
Edit5.Text := FormatFloat( '#.0', Lr[1] );
Edit6.Text := FormatFloat( '#.0', Lr[2] );
end;