I have one unit which I want to be compiled under any Delphi version from let's say Delphi 2006.
It has next code which have problems compiling:
uses
graphics; // for previous versions can not be compiled on Delphi XE
uses
vcl.graphics; // compiled on Delphi XE but can not compile on previous version
And functions StrLen, StrCopy produce "deprecated. moved to AnsiString" warning.
Question is: How to sort it all out? From which compiler version graphics become vcl.graphics, and StrLen moved to AnsiStrings? To create next code:
uses
{$if CompilerVersion < ??}graphics{$ifelse}vcl.graphics{$ifend};
The
Graphicsunit was renamed toVcl.Graphicsin XE2, when Unit Scope Names were first introduced.What's New in Delphi and C++Builder XE2
You do not need to use an
{$IF}statement to write cross-version VCL code. Yourusesclause can continue to use theGraphicsunit name by itself:Just make sure that Vcl is included in the Unit scope names list in the Project Options of XE2+ projects (which it should be by default).
This is documented (in fact, the documentation even uses the
Graphicsunit as an example):Delphi Compiler Project Options | Delphi Compiler
If you choose to use an
{$IF}statement, the correct syntax is:Or:
As for the
PAnsiCharversions ofSysUtils.StrLen()andSysUtils.StrCopy(), they were deprecated and moved to theSystem.AnsiStringsunit in XE4 (RTLVersion=25.0). For example:Lastly, note that
{$IF}was introduced in Delphi 6, so if you need to support Delphi 5 or earlier, you have to wrap{$IF}statements in an{$IFDEF CONDITIONALEXPRESSIONS}block.