Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

Introducing the Delphi Upgrade Advisor Wizard

rad13advisor cover

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.

How To Install

The Delphi Projects Upgrade Advisor package is available in the GetIt package manager for customers with an active update subscription:

rad13advisor 01

Once installed you can find a new menu item under Tools, as shown here:

rad13advisor 02

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:

rad13advisor 03

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:

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:

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:

Now once you remove that entry, you’re likely going to get errors like:

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)

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:

rad13advisor 04

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:

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.

See What's New in RAD Studio 13 Florence The AI Codecamp: Learn, Code, Create

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Marco is one of the RAD Studio Product Managers, focused on Delphi. He's the best selling author of over 20 books on Delphi.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES