Show: Object Pascal C++
Display Preferences

E2026 Constant expression expected (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

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.

Personal tools
In other languages