In Delphi 7, why can I assign a value to a const?

Posted by Blorgbeard on Stack Overflow See other posts from Stack Overflow or by Blorgbeard
Published on 2008-09-08T00:34:45Z Indexed on 2010/04/15 16:23 UTC
Read the original article Hit count: 323

Filed under:
|

I copied some Delphi code from one project to another, and found that it doesn't compile in the new project, though it did in the old one. The code looks something like this:

procedure TForm1.CalculateGP(..)
const
   Price : money = 0;
begin
   ...
   Price := 1.0;
   ...
end;

So in the new project, Delphi complains that "left side cannot be assigned to" - understandable! But this code compiles in the old project. So my question is, why? Is there a compiler switch to allow consts to be reassigned? How does that even work? I thought consts were replaced by their values at compile time?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about constant