Delphi – uses controls unit in all versions of Delphi, VCL, FMX

This shows how to USE the CONTROLS unit in a way that will work for all versions of Delphi (old and new) as well as VCL and FireMonkey.,

You can use variations of this for other units

There are other ways to achieve this, which I wont go into here.

The technique listed here is useful when developing Delphi controls or units that you will provide to other people. It works without requiring any changes to their project or IDE options.

uses
       {$IF CompilerVersion >= 23.0} // 23 is Delphi XE2
            {$IF not declared(FireMonkeyVersion)}
                 VCL.Controls,
            {$ELSE}
                 FMX.Controls,
            {$IFEND}
       {$ELSE} // VCL prior to XE2
            Controls,
       {$IFEND}
       MyOtherUnits;

+1 this post

If you like this post, please up-vote it on BeginEnd – Thank You

About The Author

scott_circle
The Usual Suspect
– Scott Hollows –

  • Oracle and Delphi software developer.
  • Australian Delphi User Group
    – Western Australia Branch Manager
    – National committee member
    – Past president
blogemaillinkedinlogo

Author: Scott Hollows

Enterprise software developer based in Perth, Western Australia. Oracle, Delphi, Data Warehouse design and ETL, Data Architect, Business Intelligence, Oracle performance tuning. Oracle ApEx, Discoverer, BI Publisher, OBIEE, Forms, Reports, SQL, PLSQL Australian Delphi User Group (ADUG) - WA branch manager and past national president LinkedIn www.linkedin.com/in/scotthollows

One thought on “Delphi – uses controls unit in all versions of Delphi, VCL, FMX”

  1. You could simply add “Controls” without the prefix and let the IDE/compiler figure it out using the Unit Scope Names configuration option of the project.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s