Вопрос

Я хочу заполнить последние три правки элементами 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;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top