【问题标题】:Delphi: Is there a tool that can remove conditional directives for particular conditional symbols?Delphi:是否有可以删除特定条件符号的条件指令的工具?
【发布时间】:2012-10-18 02:51:52
【问题描述】:

我有许多单元包含许多条件指令块,例如:

{$IFDEF DELPHI6ANDLOWER}
  *Do something 1*
{$ELSE}
  *Do something 2*
{$ENDIF}

现在,我决定放弃对 Delphi 6 (VER140) 及更低版本的支持。

有没有一种工具可以施展魔法?希望上面的代码变成:

  *Do something 2*

我已经测试过 ModelMaker、CnPack、GExperts,但没有一个能做到这一点。

【问题讨论】:

    标签: delphi


    【解决方案1】:

    Delphi Inspiration 的免费软件程序 DIPP 可以删除条件。

    http://www.yunqa.de/delphi/doku.php/products/dipp/index

    【讨论】:

      【解决方案2】:

      首先,我确认 @ctomita 提到的DIPP 工具非常适合我的情况。

      其次,我认为与人们分享我如何使用该工具解决我的案例示例可能会很有用。

      Test1.pas

      //--------------------------------------
      {$IFDEF ONE}
        ShowMessage('If ONE was defined');
        WriteLn('If ONE was defined');
        {$IFDEF ONE_ONE}
          ShowMessage('If ONE_ONE was defined');
          WriteLn('If ONE_ONE was defined');
        {$ENDIF}
      {$ELSE}
        ShowMessage('If ONE was not defined');
        WriteLn('If ONE was not defined');
      {$ENDIF}
      //--------------------------------------
      {$IFNDEF ONE}
        ShowMessage('If ONE was not defined');
        WriteLn('If ONE was not defined');
      {$ELSE}
        ShowMessage('If ONE was defined');
        WriteLn('If ONE was defined');
      {$ENDIF}
      //--------------------------------------
      

      要从 Test1.pas 中删除所有 ONE 条件块,并使用 假设 as if 有一个名为ZERO 当前已定义,请从命令提示符使用此命令:

      dipp -o -c -dZERO -h-ONE "Test1.pas" "Test1_output.pas"
      

      Test1_output.pas

      //--------------------------------------
      
        ShowMessage('If ONE was not defined');
        WriteLn('If ONE was not defined');
      
      //--------------------------------------
      
        ShowMessage('If ONE was not defined');
        WriteLn('If ONE was not defined');
      
      //--------------------------------------
      

      请注意,当指定 -c 选项时,DIPP 会跳过未定义条件包围的代码,根据已定义条件插入包含文件。换句话说,DIPP 会像编译器一样处理源代码。

      【讨论】:

        猜你喜欢
        • 2021-10-23
        • 2019-07-30
        • 2019-06-21
        • 2021-08-17
        • 1970-01-01
        • 1970-01-01
        • 2010-11-26
        • 1970-01-01
        • 2022-01-22
        相关资源
        最近更新 更多