delphi - 是否可以将整个 const block 标记为已弃用?

标签 delphi delphi-7

我知道您可以使用将单个常量标记为已弃用

const
  NotDeprConst1 = 1;
  DeprConst = 2 deprecated;
  NotDeprConst2 = 2;

但是,您可以将整个 const block 标记为已弃用,而不逐一标记常量吗?

我想做这样的事情:

const deprecated
  DeprConst1 = 1;
  DeprConst2 = 2;
  DeprConst3 = 3;

但是这不会编译(编译器将“已弃用”视为标识符)。

或者也许有一个编译器指令:

{$DEPRECATED ON}
const
  DeprConst1 = 1;
  DeprConst2 = 2;
  DeprConst3 = 3;
{$DEPRECATED OFF}

Embarcadero 的提示指令 documentation说你可以用提示标记任何声明(例如已弃用),但没有详细说明。

最佳答案

正如您所发现的,const block 不能一次性被弃用。也没有像您推测的那样的编译器指令。然而,documentation你指的是说

When a hint directive appears in a unit declaration, it means that the hint applies to everything in the unit. For example, the Windows 3.1 style OleAuto.pas unit on Windows is completely deprecated. Any reference to that unit or any symbol in that unit produces a deprecation message.

通过将已弃用的 const 声明移至新单元并将该单元标记为已弃用,您可以一次性弃用大量声明。然后,当然,您仍然需要修复单元引用。是否省力由你决定。

关于delphi - 是否可以将整个 const block 标记为已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27296111/

相关文章:

delphi - 我可以使用什么工具来合并 wsdl 和 xsd 文件?

delphi - 将 Delphi 7 pgm 限制到公司 LAN

delphi - 需要释放 SHGetDesktopFolder 返回的 IShellFolder 接口(interface)吗?如何?

string - 如何判断Delphi变体是否为空字符串?

delphi - 随机化多个字符串列表

delphi - 鼠标缩放: marquee color

delphi - 如何在同一项目组中的项目之间共享单元?

delphi - MOUSE_WHEEL 增量始终为正

delphi - 如何写入控制台窗口进行调试?

delphi - 自动化服务器使用 CreateOleObject 启动两次,但并非每次都启动