Recent

Author Topic: Radiogroup program  (Read 1659 times)

godik

  • New Member
  • *
  • Posts: 23
Radiogroup program
« on: October 29, 2018, 10:53:12 am »
Hello i have problem with this program

procedure TForm1.RadioGroup1Click(Sender: TObject);
var a,b,V,S,O:real;
begin
a:=Floattostr(Edit1.Text);
b:=Floattostr(Edit2.Text);
if RadioGroup1.ItemIndex=0 then V:=a*a*a;
Edit3.Text.Caption:=StrtoFloat(Edit3.Text);
else if RadioGroup1.ItemIndex=1 then S:=(a*a)*6;
Edit3.Text.Caption:=StrtoFloat(Edit3.Text);
else if RadioGroup1.ItemIndex=2 then O:=a+b;
Edit3.Text.Caption:=StrtoFloat(Edit3.Text);
end;

end. 


It shows me errors but i dont know why

fred

  • Full Member
  • ***
  • Posts: 201
Re: Radiogroup program
« Reply #1 on: October 29, 2018, 11:09:24 am »
Perhaps Floattostr should be StrToFloat and vice versa?

Postman

  • Newbie
  • Posts: 1
Re: Radiogroup program
« Reply #2 on: October 29, 2018, 11:13:21 am »
Hello, godik.

1. wrong - a:=Floattostr(Edit1.Text);
right -  a:=StrToFloat(Edit1.Text);
because Edit1.Text is string

2. wrong - b:=Floattostr(Edit2.Text);
right - b:=StrToFloat(Edit2.Text);
because Edit2.Text is string

3. Edit3.Text.Caption:=StrtoFloat(Edit3.Text);
What is Edit3.Text.Caption?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Radiogroup program
« Reply #3 on: October 29, 2018, 11:13:24 am »
You don't say what the errors are, but fred has pinpointed one problem.
Try this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.RadioGroup1Click(Sender: TObject);
  2. var
  3.   a, b: Double;
  4. begin
  5.   a := StrToFloatDef(Edit1.Text, 0);
  6.   b := StrToFloatDef(Edit2.Text, 0);
  7.   case RadioGroup1.ItemIndex of
  8.     0: Edit3.Text := FloatToStr(a*a*a);
  9.     1: Edit3.Text := FloatToStr(a*a*6);
  10.     2: Edit3.Text := FloatToStr(a + b);
  11.     else Edit3.Text := 'unexpected index ' + IntToStr(RadioGroup1.ItemIndex);
  12.   end;
  13. end;

nouzi

  • Sr. Member
  • ****
  • Posts: 296
Re: Radiogroup program
« Reply #4 on: October 29, 2018, 11:21:10 am »
problem in edit3.text.Caption try change to  edit3.text only
My English is  bad
Lazarus last version free pascal last version
Lazarus trunk  free pascal trunk 
System : Linux mint  64bit  Windows 7 64bit

 

TinyPortal © 2005-2018