6

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.
8
  • This seems pretty hard to believe! Would be a compiler bug if it is so. Commented Dec 30, 2015 at 12:41
  • The code compiles successfully in Delphi XE5 Commented Dec 30, 2015 at 13:01
  • @DavidHeffernan Oh!... O_O Commented Dec 30, 2015 at 13:08
  • 1
    Compiles in XE2 but not Delphi 2007. This link might be interesting: stackoverflow.com/questions/3780235/… Commented Dec 30, 2015 at 13:41
  • 1
    perhaps it is a compiler bug stemming from a special-case handling of PChar Commented Dec 30, 2015 at 14:19

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.