Delphi Error – E2197 Constant object cannot be passed as var parameter

Delphi Compiler Error

E2197 Constant object cannot be passed as var parameter

Reason for the Error & Solution

This error message appears when you try to send a constant as a var or out parameter for a function or procedure.

The following example uses a constant as var parameter.

program Project1;

uses
  SysUtils;

const
  c: Integer = 2;

procedure MyProc(var c: Integer);
begin

end;

begin
  MyProc(c);                (*Error message here*)
end.

To solve this kind of problem, you can declare another variable and assign the value of the constant to the variable.

program Project2;

uses
  SysUtils;

const
  c: Integer = 2;

var
  a: Integer;

procedure MyProc(var a: Integer);
begin

end;

begin
  a := c;
  MyProc(a);                (*This is fine*)
end.

Share:

Leave A Reply

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

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...