Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot pass typed char array to open array of char?

When compiled under Delphi 7 or Delphi XE, the code below complains

[DCC Error] Project1.dpr(25): E2010 Incompatible types: 'array of Char' and 'TAChar'

According to Rudy's article, it should be allowed to pass typed array to open array ?

Furthermore, why does it not complain for 'array of Boolean' and 'TABoolean' ?

Many thanks for help !

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TAChar = array of Char;
  TABoolean = array of Boolean;

procedure Test1(const CharArr: array of Char);
begin
end;

procedure Test2(const BoolArr: array of Boolean);
begin
end;

var
  Arr1: TAChar;
  Arr2: TABoolean;
begin
  try
    Test1(Arr1);  //  <------- Does not compile in Delphi 7 & XE
    Test2(Arr2);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
like image 277
SOUser Avatar asked Dec 30 '15 12:12

SOUser


1 Answers

The code in the question is valid. Any compiler that refuses to compile it is defective. Probably there is little point submitting a bug report because modern versions will compile this code.

If you cannot move to a compiler that is not defective then you will have to work around the defect. Sertac's answer to a similar question demonstrates one such work around: https://stackoverflow.com/a/3781425/505088

like image 71
David Heffernan Avatar answered Nov 10 '22 05:11

David Heffernan