Question

Je veux remplir les trois dernières éditions avec les éléments de r.D'une manière ou d'une autre, la valeur de i ne change pas.Jetez un coup d'oeil s'il vous plait!

    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.
Était-ce utile?

La solution

Votre code contient beaucoup de code inutile et bogué.Je vais donc le corriger dans la mesure où je peux le faire à partir des informations données.J'ai ajouté un préfixe L à tous locale variables

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;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top