如何弃用 Delphi 中的数组类型声明?
How to deprecate an Array type declaration in Delphi?
我需要将一个数组类型声明标记为弃用(好吧,实际上不止一个),以帮助我们的代码迁移到更高级和更灵活的TArray<T>
泛型。
我试过这个:
type
TArrayChars = array of Char deprecated;
但我遇到编译错误:E2029 ';' expected but identifier 'deprecated' found
如果声明的类型不是数组,同样有效,例如:
type
TFieldChars = set of Char deprecated;
请注意,这在设计上应该是可行的。
我错过了什么?
这似乎是 Delphi 中的一个错误(至少 10.1 柏林和 10.2 东京)。
我接受的答案提出了一个简洁的解决方法,即:
type
TArrayCharsOld = array of Char;
TArrayChars = TArrayCharsOld deprecated;
我会向 Embarcadero 提交错误报告。
这是我提交的 Embarcadero QC 问题:
https://quality.embarcadero.com/browse/RSP-18316
没什么好说的。不能将动态数组类型声明标记为已弃用。
我认为这是一个缺陷。 documentation 表示:
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.
您的动态数组类型声明符合此处列出的要求,因为它是类型声明。
有办法绕过它(至少在 10.1 柏林)。
type
TArrayCharsOld = array of Char;
TArrayChars = TArrayCharsOld deprecated;
编译。
我需要将一个数组类型声明标记为弃用(好吧,实际上不止一个),以帮助我们的代码迁移到更高级和更灵活的TArray<T>
泛型。
我试过这个:
type
TArrayChars = array of Char deprecated;
但我遇到编译错误:E2029 ';' expected but identifier 'deprecated' found
如果声明的类型不是数组,同样有效,例如:
type
TFieldChars = set of Char deprecated;
请注意,这在设计上应该是可行的。
我错过了什么?
这似乎是 Delphi 中的一个错误(至少 10.1 柏林和 10.2 东京)。
我接受的答案提出了一个简洁的解决方法,即:
type
TArrayCharsOld = array of Char;
TArrayChars = TArrayCharsOld deprecated;
我会向 Embarcadero 提交错误报告。
这是我提交的 Embarcadero QC 问题: https://quality.embarcadero.com/browse/RSP-18316
没什么好说的。不能将动态数组类型声明标记为已弃用。
我认为这是一个缺陷。 documentation 表示:
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.
您的动态数组类型声明符合此处列出的要求,因为它是类型声明。
有办法绕过它(至少在 10.1 柏林)。
type
TArrayCharsOld = array of Char;
TArrayChars = TArrayCharsOld deprecated;
编译。