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 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...