Board index » delphi » T-Edit

T-Edit

Please help

I am a novice Delphi programmer and have a problem with edit boxs. I
need a form with 3 edit components and a single button, what I require
is for the user to enter a numerical value in box A and another one in
box B, Then perform a simple calculation such as A+B and display the
result in the third box when the user clicks the button on the form. I
would appreciate any help or Delphi code. Please
E-mail me or post back to this newsgroup.

Thanks

E-mail : ZDEE...@BAY.CC.KCL.AC.UK

 

Re:T-Edit


Quote
Al wrote:

> Please help

> I am a novice Delphi programmer and have a problem with edit boxs. I
> need a form with 3 edit components and a single button, what I require
> is for the user to enter a numerical value in box A and another one in
> box B, Then perform a simple calculation such as A+B and display the
> result in the third box when the user clicks the button on the form. I
> would appreciate any help or Delphi code. Please
> E-mail me or post back to this newsgroup.

        Assuming the "numeric values" are integers: You give the
button an OnClick handler like so:

begin
        Edit3.Text:=
           IntToStr(StrToInt(Edit1.Text) + StrToInt(Edit2.Text));

For floating-point values you might try FloatToStr and StrToFloat.

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:T-Edit


  I would do it something like this (put together very quickly):

var
  Value1, Value2, Value3: Double;

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    Value1 := StrToFloat(Edit1.Text);
    try
      Value2 := StrToFloat(Edit2.Text);
      Value3 := Value1 + Value2;
      Edit3.Text := FloatToStr(Value3);
    except on EConvertError do
    begin
      Edit2.SetFocus;
      MessageDlg('This is not a valid number',mtError,[mbOK],0);
    end;
    end;
  except on EConvertError do
  begin
    Edit1.SetFocus;
    MessageDlg('This is not a valid number',mtError,[mbOK],0);
  end;
  end;
end;

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Al <zdee...@bay.cc.kcl.ac.uk> wrote in article
<3312FC2C.4...@bay.cc.kcl.ac.uk>...

Quote
> Please help

> I am a novice Delphi programmer and have a problem with edit boxs. I
> need a form with 3 edit components and a single button, what I require
> is for the user to enter a numerical value in box A and another one in
> box B, Then perform a simple calculation such as A+B and display the
> result in the third box when the user clicks the button on the form. I
> would appreciate any help or Delphi code. Please
> E-mail me or post back to this newsgroup.

> Thanks

> E-mail : ZDEE...@BAY.CC.KCL.AC.UK

Other Threads