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+.
Delphi equivalent to Free Pascal's FPC define?
-
28-09-2022 - |
Question
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?
Solution
OTHER TIPS
Documentation predefined conditionals
reveals that DCC
is a predefined symbol that could be used to separate Delphi from other compilers.
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}