
The new Delphi Upgrade Advisor wizard in RAD Studio 13 enables developers to identify meaningful changes to project configuration and code, significantly improving compilation time and the overall code tooling experience. The wizard is available as a separate GetIt package. Once installed, it will add a menu item to the IDE.
Besides providing some specific suggestions, the Delphi Upgrade Advisor wizard comes with reFind scripts you can use to clean up the project’s uses statements.
Table of Contents
How To Install
The Delphi Projects Upgrade Advisor package is available in the GetIt package manager for customers with an active update subscription:
Once installed you can find a new menu item under Tools, as shown here:
The Wizard
The wizard works on the active project. For this reason, before you activate it, you should open an existing project you want to test. In general terms you should open an old project, not one created with RAD Studio 13 or 12, as those will probably not include the old coding styles worth fixing.
This is the UI of the wizard:
As you can see, the wizard offers 4 different operations you can enable or disable. Three of them work directly on the project and the IDE configuration. The fourth requires generating a separate file first. Let’s cover each of these options.
Check for Invalid Path
Having invalid paths in the search or library path can slow down compilation, as the operating system calls to check for or try to open an invalid location are expensive. This is a fairly minor issue, but with many invalid paths and hundreds of units to look for, it can affect performance. This is an example of the output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Start of the task: Check for Invalid Library Paths [OSX64] Directory not found "$(BDSUSERDIR)Imports$(Platform)" [OSX64] Directory not found "$(BDSCOMMONDIR)Dcp$(Platform)" [OSX64] Directory not found "$(BDSCOMMONDIR)Bpl$(Platform)" [Android64] Directory not found "$(BDSCOMMONDIR)Dcp$(PLATFORM)" [Win64] Directory not found "$(BDSUSERDIR)Imports$(Platform)" [Win64] Directory not found "$(BDSCOMMONDIR)Dcp$(Platform)" [OSXARM64] Directory not found "$(BDSUSERDIR)Imports$(Platform)" [OSXARM64] Directory not found "$(BDSCOMMONDIR)Dcp$(Platform)" [OSXARM64] Directory not found "$(BDSCOMMONDIR)Bpl$(Platform)" [iOSDevice64] Directory not found "$(BDSCOMMONDIR)Dcp$(PLATFORM)" [iOSSimARM64] Directory not found "$(BDSCOMMONDIR)Dcp$(PLATFORM)" [Win64x] Directory not found "$(BDSUSERDIR)Imports$(Platform)" [Win64x] Directory not found "$(BDSCOMMONDIR)Dcp$(Platform)" [Linux64] Directory not found "$(BDSCOMMONDIR)Dcp$(Platform)" [Linux64] Directory not found "$(BDSCOMMONDIR)Bpl$(Platform)" The task is completed Start of the task: Check for Invalid Project Search Paths Current Project: ViewDateDemo.dproj [Win32-Debug] Directory not found "C:/foo/bar" The task is completed |
As you can see, it found an invalid path in the project search path. We recommend removing any illegal folder from your configurations.
Unit Aliases
Unit aliases were introduced in Delphi 2 for compatibility with Delphi 1 and they remained a predefined configuration for new projects for many years afterwards. If you have been maintaining old projects and moving them to newer versions, you might have this leftover configuration, which the compiler needs to check very frequently when you use units.
Over the years, other unit aliases have been added to overcome changes in the unit’s structure. Again, this is a sample output for an old project:
1 2 3 4 |
Start of the task: Check For Unit Aliases Current Project: ViewDateDemo.dproj [Win32-Debug] Aliases were found "Actions=ActnList;ImageList=Controls" The task is completed |
We recommend replacing unit names with the correct ones and removing the unit aliases configurations in the project options. To replace units, you can use the specific reFind script included with the GetIt package of the wizard and covered later.
Unqualified Unit Names
The third test is for unqualified unit names, like “uses Forms” rather than “uses VCL.Forms. Having to try all prefixes for all units adds a lot to the compiler. Therefore we recommend cleaning up. Notice that the tool doesn’t search the actual code for unqualified unit names. It checks the project configuration, recommending removing that entry:
This is a sample output:
1 2 3 4 5 |
Start of the task: Check For Unqualified Unit Names Current Project: ViewDateDemo.dproj [All-Base] Unit scope names were found "Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi" [Win32-Base] Unit scope names were found "System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde" The task is completed |
Now once you remove that entry, you’re likely going to get errors like:
1 |
F2063 Could not compile used unit 'Forms' at line 6 (6:31) |
Again, to correct the unit names in the uses statements, you can use the specific reFind script included with the GetIt package of the wizard and covered later.
Circular Unit References
The fourth option is checking for circular unit references. In this case the process has two steps. First you have to enable the generation of the GraphViz file in the compiler options (see https://docwiki.embarcadero.com/RADStudio/Florence/en/GraphViz_file_export_for_the_Delphi_Compiler), compile the project and next you have to select the file in the wizard.
This is a sample output, excluding system libraries (you can also exclude VCL libraries from the GraphViz file with the additional –graphviz-exclude parameter)
1 2 3 4 5 6 7 8 |
Start of the task: Check for Circular Unit References DateF has a circular uses statement: └─DatesUnit (interface) └─DateF (implementation) DatesUnit has a circular uses statement: └─DateF (implementation) └─DatesUnit (interface) The task is completed |
By examining the GraphViz file, the wizard can spot cycles and display them, something very complex to do for a very large graph.
Now some uses unit cycles are unavoidable, but you should review the cycles in your applications and consider which can be avoiding by improving the code organization and architecture. In general terms, this is a good exercise to help you remove dependencies across modules.
The Wizard, Again
This is the actual wizard in action:
The Uses Statement Refind Script
There is an additional file that ships in the GetIt package and that you can find in the package folder (a folder you can open with a new command in the GetIt package manager dialog box). It’s called RenameUnits.txt and it’s a script you can pass to the reFind utility to convert units for both aliases and unqualified units. The script (which you can of course adapt to your specific project needs) has hundreds of lines like:
1 2 3 4 5 6 7 |
#replaceunit ABAccessibility->Vcl.ABAccessibility #replaceunit ADOConEd->Data.Win.ADOConEd #replaceunit ADOConst->Data.Win.ADOConst #replaceunit ADODB->Data.Win.ADODB #replaceunit ADOInt->Winapi.ADOInt #replaceunit ADSTypes->Web.Win.ADSTypes #replaceunit AVFoundation->Macapi.AVFoundation |
We recommend running reFind with this script on your entire project, after making a copy of the original source. Once this is done, you should be able to remove the project’s settings flagged by the wizard and have an application that compiles a little faster.
Conclusion
The Delphi Projects Upgrade Advisor can help you cleanup existing old (and large) Delphi applications, so that their more modern code can be processed faster by the compiler (and the DelphiLSP engine). over the years we have witnessed some customers with large applications benefit from similar transformations, and we have now released the tools to help you do the same much faster.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Thanks for providing this tool.
Unfortuately it fails on the Circular Unit References check with message:
An exception occurred: Kind “0” is expected at position [1017:2]
Hi Achim. This is obviously not correct behavior by the tool.
Could you possibly go to https://qp.embarcadero.com log a bug report and attach the generated GraphViz file, if there are no company secrets in it? Otherwise, you can email the file directly to me, to avoid sharing publicly – my email is [email protected] – and I will pass it on to the team for them to examine.
To find out about the GraphihViz generator go here: https://docwiki.embarcadero.com/RADStudio/Florence/en/GraphViz_file_export_for_the_Delphi_Compiler