Assignment with no assignment operator compiles with no error

90 views Asked by At

I've found that if you have an assignment with no assignment operator in Delphi 2007 then it compiles with no error as long as it is immediately after a begin in the code:

procedure TForm1.Button1Click(Sender: TObject);
var
  X: word;
begin
  X := 0;
  begin
    X + 1;
  end;
end;

'X + 1' is not a valid statement in Delphi and yet it compiles.

It is the same for other operators. Take the begin away and you get the error :

"[DCC Error] Unit1.pas(32): E2014 Statement expected

But expression of type Integer found:

procedure TForm1.Button1Click(Sender: TObject);
var
  X: word;
begin
  X := 0;
  X + 1;
end;

Which is what I would expect. Does anyone have an explanation for this error?

0

There are 0 answers