How to abandon an array type declaration in Delphi?

I need to point out an outdated array type declaration (well, actually, more than one) to help port our code to the more advanced and flexible TArray<T> .

I tried this:

 type TArrayChars = array of Char deprecated; 

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

The same thing works if the declared type is not an array, for example:

 type TFieldChars = set of Char deprecated; 

Please 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 offers a neat workaround , i.e.:

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

I will write a bug report in Embarcadero.


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

+7
arrays deprecated delphi
source share
2 answers

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

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

compiles.

+10
source share

Nothing to say. Dynamic array type declarations cannot be marked as deprecated.

I consider this a defect. The documentation says:

The hint directive platform, obsolete, and the library can be attached to any declaration. These directives will be compilation time. Hint directives can apply to type declarations, variable declarations, class declarations, interfaces and structures, field declarations within classes or records, procedures, functions and method declarations and unit declarations.

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

+5
source share

All Articles