5

Is there a compiler define that tells if source code is compiled with delphi, in the sense of an equivalent to the FPC define in Free Pascal?

I am developing a unit that should be compatible with three Pascal compilers (Lazarus / Free Pascal, Delphi and winsoft PocketStudio). There are some differences among the compilers, therefore I would like to provide some critical parts of the code in a compiler-specific version.

For Free Pascal I can write

{$IFDEF FPC}
  DoSomething;
{$ENDIF}

but what is the equivalent for Delphi?

jwdietrich
  • 474
  • 6
  • 17
  • 3
    See documentation for [`predifined conditionals`](http://docwiki.embarcadero.com/RADStudio/XE5/en/Conditional_compilation_(Delphi)#Predefined_Conditionals). DCC perhaps. – LU RD Jan 16 '14 at 23:37
  • 1
    There's none for Delphi. Is there one for PocketStudio? If there is, you can use `{$IFNDEF FPC}', '{$IFNDEF POCKET_STUDIO}', '{$ELSE}{$DEFINE DELPHI}`. – Ken White Jan 16 '14 at 23:41
  • 1
    @KenWhite: There is one for Delphi - `DCC` - but only in XE and later. – Remy Lebeau Jan 16 '14 at 23:51
  • @Remy: I know, but the question has no version tags. There is none for Delphi in general. – Ken White Jan 16 '14 at 23:52

3 Answers3

8

The DCC define was added to the Delphi compiler in XE2. Prior to that, you had to use {$IFDEF VERxxx} statements to check for the presence of individual VERxxx defines for each version of Delphi, or an {$IF DECLARED(CompilerVersion)} statement for Delphi 6+.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
2

Documentation predefined conditionals reveals that DCC is a predefined symbol that could be used to separate Delphi from other compilers.

LU RD
  • 34,438
  • 5
  • 88
  • 296
  • 5
    Only in Delphi XE and later, as `DCC` did not exist prior to XE. – Remy Lebeau Jan 16 '14 at 23:50
  • Thanks, but this should be solvable. – jwdietrich Jan 16 '14 at 23:52
  • 3
    It is "solvable", just ugly unless PocketStudio has something that can be tested for so Delphi is a fallback when nothing else is detected. Indy gets around this by manually defining `DCC` for every Delphi version prior to XE, that way it can always test for `DCC` when needed. – Remy Lebeau Jan 16 '14 at 23:56
  • Dropping versions that don't $if defined() also helps tremendously in simplifying include files. – Marco van de Voort Jan 17 '14 at 12:53
0

Thanks for your hints.

Based on them I can now find out, if the code is compiled with Delphi or Free Pascal with the following statements:

{$IFDEF VER80}   {Delphi 1}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER90}   {Delphi 2}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER100}   {Delphi 3}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER120}   {Delphi 4}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER130}   {Delphi 5}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER140}   {Delphi 6}
{$DEFINE DELPHI}
{  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER150}   {Delphi 7}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER160}   {Delphi 8}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER170}   {Delphi 9}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER180}   {Delphi 10}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER185}   {Delphi 11 - Spacely}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER190}   {Delphi 11 - Highlander and Delphi 12}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER200}   {Delphi 12}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF VER210}   {Delphi 2010}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF DCC}   {Delphi XE and newer versions}
{$DEFINE DELPHI}
  DoSomeSpecificStuff;
{$ENDIF}

{$IFDEF FPC]   {Lazarus and Free Pascal}
  DoSomeSpecificStuff;
{$ENDIF}
jwdietrich
  • 474
  • 6
  • 17
  • Introducing $if declared here for versions >=6 will reduce redundant parts of DoSpecificStuff, same as DCC – Marco van de Voort Feb 26 '14 at 08:51
  • You are right, but this formulation provides a form of backwards-compatibility. Old Pascal compilers don't support more elaborate forms of {$IFDEF} constructs. – jwdietrich Feb 27 '14 at 07:28