RAD Studio (Common)
ContentsIndex
PreviousUpNext
E2026: Constant expression expected (Delphi)

The compiler expected a constant expression here, but the expression it found turned out not to be constant.

program Produce;
const
  Message = 'Hello World!';
  WPosition = Pos('W', Message);
begin
end.

The call to Pos is not a constant expression to the compiler, even though its arguments are constants, and it could in principle be evaluated at compile time.

program Solve;
const
  Message = 'Hello World!';
  WPosition = 7;
begin
end.

So in this case, we just have to calculate the right value for WPosition ourselves.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!