Rolan Wagener
Rolan Wagener

Reputation: 49

Why does the following code result in missing operator or semicolon compilation error?

I have the following code in a form:

procedure TForm1.RoundClick(Sender: TObject);
var   
  Number : real;            

begin
  rNumber := Number.Value;
  ShowMessage('Round(rNumber) = '+FloatToStr(Round(rNumber)));  
end;

This results in the following compiler error:

[Error] Unit1.pas(39): Missing operator or semicolon

I don't see any missing semicolons and I don't know where to put an operator, the error is at my rNumber.

Upvotes: 0

Views: 354

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

The problem is that your class has a button whose name is Round. So when you write Round(...), the compiler sees Round as a button rather than a function.

You can do either of the following:

  1. Rename the button to avoid the name clash.
  2. Use a fully qualified name to resolve the name clash. In this case you would write System.Round because the Round function is defined in the System unit.

Upvotes: 4

Related Questions