18

In Delphi 2010, if I want to do this:

{$IFDEF VER999}
//some delphi 2010-specific code here
{$ENDIF}

What version # do I need to use in place of "999"?

ulrichb
  • 19,610
  • 8
  • 73
  • 87
JosephStyons
  • 57,317
  • 63
  • 160
  • 234

5 Answers5

58

Here's the list of compiler versions:

{$IFDEF VER40}  - Turbo pascal 4
{$IFDEF VER50}  - Turbo pascal 5
{$IFDEF VER55}  - Turbo pascal 5.5
{$IFDEF VER60}  - Turbo pascal 6
{$IFDEF VER70}  - Borland pascal 7 (And turbo pascal 1.5 for windows)
{$IFDEF VER80}  - Delphi 1
{$IFDEF VER90}  - Delphi 2
{$IFDEF VER100} - Delphi 3
{$IFDEF VER120} - Delphi 4
{$IFDEF VER130} - Delphi 5
{$IFDEF VER140} - Delphi 6
{$IFDEF VER150} - Delphi 7
{$IFDEF VER160} - Delphi 8
{$IFDEF VER170} - Delphi 2005
{$IFDEF VER180} - Delphi 2006
{$IFDEF VER180} - Delphi 2007
{$IFDEF VER185} - Delphi 2007
{$IFDEF VER200} - Delphi 2009
{$IFDEF VER210} - Delphi 2010
{$IFDEF VER220} - Delphi XE
{$IFDEF VER230} - Delphi XE2
{$IFDEF VER240} - Delphi XE3
{$IFDEF VER250} - Delphi XE4
{$IFDEF VER260} - Delphi XE5
{$IFDEF VER265} - Appmethod 1.0
{$IFDEF VER270} - Delphi XE6
{$IFDEF VER280} - Delphi XE7
{$IFDEF VER290} - Delphi XE8
{$IFDEF VER300} - Delphi 10 Seattle
{$IFDEF VER310} - Delphi 10.1 Berlin
{$IFDEF VER320} - Delphi 10.2 Tokyo

In Delphi 2007, VER180 and VER185 are both defined. This was for backward compatibility with Delphi 2006, and to make sure you could also detect D2007 specifically.

I'm not sure why they did that between '06 and '07, but not for other releases. Seems inconsistent to me (but it isn't - see Barry Kelly's comment below).

Victoria
  • 7,822
  • 2
  • 21
  • 44
JosephStyons
  • 57,317
  • 63
  • 160
  • 234
32

If you're working with Delphi 6 and later, you can use CompilerVersion:

{$IF CompilerVersion >= 18.5}
//some code only compiled for Delphi 2007 and later
{$IFEND}
Delphi 10.2 Tokyo  - 32
Delphi 10.1 Berlin - 31
Delphi 10 Seattle  - 30
Delphi XE8         - 29
Delphi XE7         - 28
Delphi XE6         - 27
Appmethod 1.0      - 26.5
Delphi XE5         - 26
Delphi XE4         - 25
Delphi XE3         - 24
Delphi XE2         - 23
Delphi XE          - 22
Delphi 2010        - 21
Delphi 2009        - 20
Delphi 2007        - 18.5
Delphi 2006        - 18
Delphi 2005        - 17
Delphi 8           - 16
Delphi 7           - 15
Delphi 6           - 14
Victoria
  • 7,822
  • 2
  • 21
  • 44
jasonpenny
  • 2,999
  • 1
  • 24
  • 23
17

{$IFDEF VER210}

Red Haze
  • 281
  • 3
  • 6
  • 5
    This file almost always contains the latest defines: http://jcl.svn.sourceforge.net/viewvc/jcl/trunk/jcl/source/include/jedi.inc?view=markup – Jeroen Wiert Pluimers Oct 15 '09 at 12:49
  • 1
    @JeroenWiertPluimers, link is dead. – Toon Krijthe Jan 27 '15 at 12:00
  • @ToonKrijthe JCL/JEDI moved from SF to GitHub a while ago. This is the one that hupefully won't move for a long time and contains all versions from Delphi 1 until the most recently released version (sometimes including the version currently in beta), including Kylix and FreePascal: https://github.com/project-jedi/jedi/blob/master/jedi.inc – Jeroen Wiert Pluimers Jan 29 '15 at 11:54
8

Here is a wiki page with conditional defines.

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
1

Along the same lines as Jason's comment if you are creating code that needs to run in current and older versions of Delphi you might want to do something like:

{$IF CompilerVersion > 18.5} 
   //Delphi 2009 or higher
   //Unicode version of code
{$ELSE}
   //Delphi 2007 and earlier
   //NON-Unicode version of code
{$IFEND}
TheSteven
  • 900
  • 8
  • 23