The Graphics
unit was renamed to Vcl.Graphics
in XE2, when Unit Scope Names were first introduced.
What's New in Delphi and C++Builder XE2
Important New Requirement: Unit Scope Names for VCL-FMX-RTL
Important: VCL-FMX-RTL units now use a dotted-prefix naming convention, such as System.Types
and Vcl.Styles
. If you have existing code that uses qualified identifiers (such as Types.IStream
), code changes may be required in order to compile.
You do not need to use an {$IF}
statement to write cross-version VCL code. Your uses
clause can continue to use the Graphics
unit name by itself:
uses
Graphics;
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 Graphics
unit as an example):
Delphi Compiler Project Options | Delphi Compiler
Specifies the unit scope names (prefixes) for Delphi dotted namespaces, to allow you to use partially qualified names in your code and in your uses
clause or #include
.
There are two ways to add a unit scope name for a Delphi unit:
Specify the fully unit-scoped name in your uses clause. For example:
uses Vcl.Graphics;
Add the unit scope name (Vcl
) to the Unit scope names field. Then the unit scope name Vcl
is automatically applied to unit names that belong to that unit scope, and you can simply specify:
uses Graphics;
The Ellipsis pop-up button opens an dialog box for selecting and adding unit scope names, as described in Common Items on Project Options Pages and Ordered list dialog box
If you choose to use an {$IF}
statement, the correct syntax is:
uses
{$IF RTLVersion >= 23}Vcl.{$IFEND}Graphics;
Or:
uses
{$IF RTLVersion >= 23}Vcl.Graphics{$ELSE}Graphics{$IFEND};
As for the PAnsiChar
versions of SysUtils.StrLen()
and SysUtils.StrCopy()
, they were deprecated and moved to the System.AnsiStrings
unit in XE4 (RTLVersion=25.0
). For example:
uses
...
{$IF RTLVersion >= 25}, AnsiStrings{$IFEND}
;
var
Src, Dest: PAnsiChar;
Len: Integer;
begin
Src := ...;
Len := {$IF RTLVersion >= 25}AnsiStrings.{$IFEND}StrLen(Src);
GetMem(Dest, Len * SizeOf(AnsiChar));
{$IF RTLVersion >= 25}AnsiStrings.{$IFEND}StrCopy(Dest, Src);
...
end;
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.