Conditional Uses Clause Considered Harmful

Everyone writing Delphi code that is meant to compile under different Delphi versions has come to the point where conditional compilation seems unavoidable. Ever so often it tends to creep into the uses clauses as well. So, what can we do when units like System.Actions and System.ImageList simple aren’t available in older Delphi versions?

Solution 1: Add an empty unit with the proper name to the project. You might end up with a collection of empty units in your version control system. But hey, it does the job.

Solution 2: Add a unit alias to the project, mapping the unknown units to existing ones you are using anyway. For the two units mentioned above some good candidates are:

  • System.Actions=Vcl.ActnList (for versions below XE3)
  • System.ImageList=Vcl.ImgList (for versions below XE8)

There are a couple of tools that fiddle around with your uses clause from time to time. They will thank you for getting rid of conditions there.

Author: Uwe Raabe

Addicted to Pascal/Delphi since the late 70's