Cannot pass typed char array to open array of char?
Asked Answered
C

1

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.
Culp answered 30/12, 2015 at 12:17 Comment(8)
This seems pretty hard to believe! Would be a compiler bug if it is so.Timikatiming
The code compiles successfully in Delphi XE5Ringnecked
@DavidHeffernan Oh!... O_OCulp
Compiles in XE2 but not Delphi 2007. This link might be interesting: #3780735Airscrew
It also compiles correctly in D2007.Ferrand
perhaps it is a compiler bug stemming from a special-case handling of PCharJannette
Unfortunately the top voted answer at that other question is terribleTimikatiming
Thank you very much for your information !Culp
T
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://mcmap.net/q/1019147/-delphi-array-of-char-and-tchararray-quot-incompatible-types-quot

Timikatiming answered 30/12, 2015 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.