* * *

Author Topic: Radiogroup program  (Read 250 times)

godik

  • New member
  • *
  • Posts: 14
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: 117
Re: Radiogroup program
« Reply #1 on: October 29, 2018, 11:09:24 am »
Perhaps Floattostr should be StrToFloat and vice versa?
Started with OmegaSoft Pascal on OS-9/68k , now Lazarus 1.8.4 / FPC 3.0.4 on Windows 7

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: 2804
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

  • New member
  • *
  • Posts: 29
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 trunk 1.9 free pascal 3.1.1 cross compile : arm-linux  i386-linux  x86_64-linux  avr-embedded  x86_64-win64  LAMW android basd on (jdk1.8.0_171 ,apache-ant-1.9.6 ,gradle-4.9-rc-1,,android sdk_r24.4.1 ,android-ndk-r10e) yes all in one
System : windows 7 64bit

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus