Backwards compatibility of uses lists

Sometimes the uses lists become an issue, when you want to keep your source code backwards compatible to older Delphi versions. This usually happens when some declaration was moved from one RTL/VCL unit to a different one. One example is TAction which has moved from the unit ActnList to the new unit Actions which was introduced sometime after Delphi 2007 and later called System.Actions.

This is a major annoyance because the Delphi IDE insists on adding System.Actions to the uses list of every form that uses TAction and descendants in any way, even though it is already there, but surrounded by an {$IFDEF}.

One workaround for this problem has been introduced with Delphi 3 (or even Delphi 2?) and is called Unit alias. Back then it was mostly a convenience issue because the units WinTypes and WinProcs were merged into the single unit Windows and the units DbiTypes, DbiProcs and DbiErrs were merged into the single unit BDE. By defining unit aliases for these, old code, that referenced e.g. WinTypes still compiled without having to change the uses list. We all have seen these entries which still automatically get added to every single new Delphi project even though they are no longer necessary.

Project-Options_Unit-Aliases

So, why not use the Uses alias list for our own purpose? Just add Actions=ActnList to the list and let the IDE add the unit Actions to the uses list whenever it likes to do that. Just make sure to remove the “System.” prefix from this entry if you want to be backwards compatible to Delphi 6 and older which did not support dotted unit names.

I have done just this with GExperts and it is really nice to no longer have to check whether Actions was added to the uses list again before committing any changes.