E2197 Constant object cannot be passed as var parameter (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi) Index

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.