Hola MoeHoward, bienvenido a los foros de
Club Delphi
Y como acostumbramos con los ingresantes, te invitamos a que leas nuestra
guía de estilo.
Si no interpreté mal la consigna, tu código está bién encaminado. Pero veo algunos detalles:
Quedaría así:
Código Delphi
[-]
procedure TForm1.Button2Click(Sender: TObject);
var
i : Integer;
LI1, LS1, ND1 : Integer; x1 : Real; RES1 : Real; VE1 : array of Real;
RE1 : Integer;
begin
LI1 := StrToInt(MaskEdit1.Text); LS1 := StrToInt(MaskEdit2.Text); RES1 := StrToFloat(ComboBox1.Text); RE1 := LS1 - LI1; ND1 := Round(RE1/RES1); SetLength(VE1, ND1);
x1 := 0;
for i := 0 to ND1-1 do
begin
VE1[i] := x1;
x1 := x1 + RES1;
end;
Memo1.Clear;
for i := 0 to ND1-1 do
Memo1.Lines.Add(Format('v[%.2d] = %3.2f',[i, VE1[i]]))
end;
Se puede optimizar un poco,
Código Delphi
[-]
procedure TForm1.Button1Click(Sender: TObject);
var
v : array of Double;
i,topInf, topSup : Integer;
Delta, Incr : Double;;
begin
topInf := StrToIntDef(MaskEdit1.Text, 0);
topSup := StrToIntDef(MaskEdit2.Text, 0);
if (TopSup-TopInf > 0) and (ComboBox1.ItemIndex <> -1) then
begin
delta := StrToFloat(ComboBox1.Items[ComboBox1.ItemIndex]);
SetLength(v, Round((TopSup-TopInf) / Delta));
Incr := 0;
for i := Low(v) to High(v) do
begin
v[i] := Incr;
Incr := Incr + Delta;
end;
Memo1.Clear;
for i := Low(v) to High(v) do
Memo1.Lines.Add(Format('v[%.2d] = %3.2f',[i,v[i]]))
end
else
ShowMessage('Revise los datos de ingreso');
end;
El control de ingreso no es muy exaustivo para no complicar el código (tal vez te convendría usar
SpinEdits en lugar de los
MaskEdits).
Saludos