Delphi Error – E2192 Constants cannot be used as open array arguments

Delphi Compiler Error

E2192 Constants cannot be used as open array arguments

Reason for the Error & Solution

Open array arguments must be supplied with an actual array variable, a constructed array or a single variable of the argument’s element type.

program Produce;

  procedure TakesArray(s : array of String);
  begin
  end;


begin TakesArray('Hello Error');
end.

The error is caused in this example because a string literal is being supplied when an array is expected. It is not possible to implicitly construct an array from a constant.

program Solve;

  procedure TakesArray(s : array of String);
  begin
  end;


begin TakesArray(['Hello Error']);
end.

The solution avoids the error because the array is explicitly constructed.