RAD Studio (Common)
ContentsIndex
PreviousUpNext
E2192: Constants cannot be used as open array arguments (Delphi)

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.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!