Delphi Error – E2026 Constant expression expected

Delphi Compiler Error

E2026 Constant expression expected

Reason for the Error & Solution

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.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...