Search code examples
delphidelphi-xe2delphi-7delphi-xe

former worked code does not work


There are code below and worked well before

unit Unit1;
  {$DEFINE _Full}
 // {$DEFINE _Trial}

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;


{$ifdef  _Trial}

_programname='abc';


{$endif}

{$ifdef  _Full}

_programname='abc';


{$endif}

but today I run Delphi and try to compile, it reported

Identifier redeclared: '_programname'

it looks like

  {$DEFINE _Full}

does not work

your comment welcome


Solution

  • Both conditionals are defined. That can be inferred from the compiler error.

    Either single line // comments do not comment out defines. Or you are defining _Trial at the project level. To the very best of my knowledge, a single line // comment will comment out a directive. So I presume that _Trial is defined at the project level.

    The idiomatic way to comment out defines is like this:

    {.$DEFINE _Trial}
    

    For an either or condition it might be simpler with a single conditional:

    {$IFDEF _Trial}
      .... stuff for trial version
    {$ELSE}
      .... stuff for full version
    {$END}
    

    All that said, perhaps your actual problem is different because the code you show does not match the error message you reported. I'd expect an error saying that a keyword was expected, but identifier _programname found. The code in the question appears to omit the const keyword before the declaration of _programname.