Delphi Upgrade Advisor Wizard
Go Up to Tools Menu
Tools > Delphi Project Upgrade Advisor
The Delphi Upgrade Advisor wizard 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.
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, a new menu item appears under Tools > Delphi Project Upgrade Advisor, as shown below:
The Wizard
The wizard works on the active project. For this reason, before activating it, open an existing project you want to test. In general terms, 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.
The following image shows the Wizard's UI:
As shown above, the wizard offers 4 different operations that one can enable or disable. The first three work directly on the project and the IDE configuration. The fourth requires generating a separate file first. The following sections cover each option.
Check for Invalid Paths
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:
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 seen above, it found an invalid path in the project search path. We recommend removing any illegal folders 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:
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
It is recommended to replace unit names with the correct ones and to remove 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.
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 significantly increases the compiler's workload. Therefore, it is recommended to clean up. Notice that the tool does not search the actual code for unqualified unit names. It checks the project configuration and recommends removing that entry.
This is a sample output:
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 that entry is removed, it is likely to get errors such as:
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.
Circular Unit References
The fourth option is checking for circular unit references. In this case, the process has two steps.
First, enable the generation of the GraphViz file in the compiler options (see Compiler Options), compile the project, and then select the file in the wizard.
This is a sample output, excluding system libraries (one can also exclude VCL libraries from the GraphViz file with the additional --graphviz-exclude
parameter).
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 identify and display cycles, a complex task for very large graphs.
The following image shows the actual wizard in action:
The Uses Statement Refind Script
There is an additional file that ships in the GetIt package, which you can find in the package folder (accessible via a new command in the GetIt package manager dialog box). It’s called RenameUnits.txt
and it’s a script that can be passed to the reFind utility to convert units for both aliases and unqualified units. The script (which you can adapt to your specific project needs) has lines like:
#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
It is recommended to run reFind with this script on your entire project, after making a copy of the original source. At this point, it is possible to remove the project's settings flagged by the wizard and have an application that compiles a little faster.