0

When I try to compilate my code a

"unit1.pas(53,1) Error: Illegal expression"

in else line appears.

procedure TForm1.Button1Click(Sender: TObject);
var x: real;
begin
x:=StrToFloat(Edit1.Text);
if x>=0
then
Label1.Caption= FloatToStr(x)
else
Label1.Caption:= Floattostr(x);
Til
  • 5,150
  • 13
  • 26
  • 34
  • 1
    In addition to anwer of MartynA see also [here](https://stackoverflow.com/a/32933320/5043424). – asd-tm Aug 04 '19 at 17:10

1 Answers1

3

What's wrong is the expression before the else. You have an equals sign = where you ought to have an assignment operator :=, as you have in the else:

if x>=0 then 
  Label1.Caption := FloatToStr(x) 
else 
  Label1.Caption:= Floattostr(x);
MartynA
  • 30,454
  • 4
  • 32
  • 73