Delphi xe6의 배열 구현
-
26-12-2019 - |
문제
마지막 세 개의 Edit를 r의 요소로 채우고 싶습니다.어쨌든 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.
해결책
귀하의 코드에는 쓸모없고 버그가 있는 코드가 많이 포함되어 있습니다.그래서 주어진 정보에서 할 수 있는 한 수정하겠습니다.접두사를 추가했습니다. 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;
제휴하지 않습니다 StackOverflow