Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deprecate an Array type declaration in Delphi?

I need to mark as deprecated an array type declaration (well, actually more than just one), in order to help migrate our code to the more advanced and flexible TArray<T> generic type.

I've tried this:

type
  TArrayChars = array of Char deprecated;

but I got a compilation error: E2029 ';' expected but identifier 'deprecated' found

The same works if the declared type isn't an array, for example:

type
  TFieldChars = set of Char deprecated;

Note that this should be feasible by design.

What am I missing?


This seems to be a bug in Delphi (at least 10.1 Berlin and 10.2 Tokyo).

My accepted answer proposes a neat workaround, that is:

type
  TArrayCharsOld = array of Char;
  TArrayChars    = TArrayCharsOld deprecated;

I'll file a bug report to Embarcadero.


This is the Embarcadero QC issue I've submitted: https://quality.embarcadero.com/browse/RSP-18316

like image 703
Bozzy Avatar asked Jun 08 '17 14:06

Bozzy


2 Answers

There is a way around it (at least in 10.1 Berlin).

type
  TArrayCharsOld = array of Char;
  TArrayChars = TArrayCharsOld deprecated;

compiles.

like image 188
Dsm Avatar answered Sep 17 '22 16:09

Dsm


There's nothing much to say. Dynamic array type declarations cannot be marked as deprecated.

I would consider this to be a defect. The documentation says:

The 'hint' directives platform, deprecated, and library may be appended to any declaration. These directives will produce warnings at compile time. Hint directives can be applied to type declarations, variable declarations, class, interface, and structure declarations, field declarations within classes or records, procedure, function, and method declarations, and unit declarations.

Your dynamic array type declaration meets the requirements listed here since it is a type declaration.

like image 22
David Heffernan Avatar answered Sep 21 '22 16:09

David Heffernan