如何在编译时检测特定的 RTL 功能?

发布于 2024-12-27 21:37:25 字数 322 浏览 2 评论 0原文

为了举例,让我们检查一下臭名昭著的 TStrings.StrictDelimiter

{$IF Declared(TStrings.StrictDelimiter)}
{$MESSAGE WARN 'Beware of TStrings.StrictDelimiter which is False by default!'}
{$IFEND}

但是,Declared 编译器内部报告条件行上的语法错误:E2029 ')' Expected but '.'找到了。 (在XE上测试)

For sake of example lets check for infamous TStrings.StrictDelimiter:

{$IF Declared(TStrings.StrictDelimiter)}
{$MESSAGE WARN 'Beware of TStrings.StrictDelimiter which is False by default!'}
{$IFEND}

However, Declared compiler intrinsic reports syntax error on conditional line: E2029 ')' expected but '.' found. (tested on XE)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风月客 2025-01-03 21:37:25

对于Delphi XE2,我使用这个:

{$IFDEF BDS9}
  Result.VersionString := 'Delphi XE2 ' +
  {$IF NOT DECLARED(Consts.SStyleFeatureNotSupported)}
    '(original release version)'
  {$ELSE} {$IF NOT DECLARED(FireMonkeyVersion)} // D2010 chokes when scope (FMX.Types) is mentioned!
    'Update 1'
  {$ELSE} {$IF NOT DECLARED(System.TestSSE)}
    'Update 2'
  {$ELSE}
    'Update 3'
    // TODO : Update this for any following update!
  {$IFEND} {$IFEND} {$IFEND}
  ;
{$ELSE}
  {$IFDEF BDS7}
     Result.VersionString := 'Delphi 2010';
  {$ELSE}
    {$MESSAGE ERROR 'Extend this!'}
  {$ENDIF}
{$ENDIF}

换句话说:我测试自任何特定delphi版本以来引入的符号是否存在。相同的构造可用于设置变量或常量或编译器定义,因此进一步的代码可以使用它们。

注意:我为过去几年安装的所有 Delphi 版本的 Source 文件夹保留了备份。通过像 BeyondCompare 这样的工具放置这些文件夹并浏览差异文件,很快就会给你一些可以测试的符号......

For Delphi XE2 I'm using this :

{$IFDEF BDS9}
  Result.VersionString := 'Delphi XE2 ' +
  {$IF NOT DECLARED(Consts.SStyleFeatureNotSupported)}
    '(original release version)'
  {$ELSE} {$IF NOT DECLARED(FireMonkeyVersion)} // D2010 chokes when scope (FMX.Types) is mentioned!
    'Update 1'
  {$ELSE} {$IF NOT DECLARED(System.TestSSE)}
    'Update 2'
  {$ELSE}
    'Update 3'
    // TODO : Update this for any following update!
  {$IFEND} {$IFEND} {$IFEND}
  ;
{$ELSE}
  {$IFDEF BDS7}
     Result.VersionString := 'Delphi 2010';
  {$ELSE}
    {$MESSAGE ERROR 'Extend this!'}
  {$ENDIF}
{$ENDIF}

In other words : I test for the existence of symbols that are introduced since any particular delphi-version. The same construct can be used to set a variable or constant or compiler define, so further code can use these instead.

Note : I keep a backup around of the Source folder for all Delphi versions that I've had installed in the past few years. Putting these folders through a tool like BeyondCompare and browsing through the differencing files, will quickly give you a few symbols that you can test for....

絕版丫頭 2025-01-03 21:37:25

不幸的是,不支持这种表达式,您必须知道在哪个 RTL/编译器版本中引入了某些功能,然后使用 预定义条件符号,例如 VERRTLVersion编译器版本等。

Unfortunately this kind of expressions aren't supported, you have to know in which RTL / compiler version some feature was introduced and then use predefined conditional symbols like VER<nnn>, RTLVersion, CompilerVersion etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文