Knowledge Base

Upgrade Delphi software: A Step-By-Step Guide with GDK Duster

As Delphi celebrates its 30th anniversary, we’re reminded of its enduring legacy in the world of software development. Many applications built decades ago continue to serve businesses and individuals, showcasing the remarkable stability of Delphi. However, staying on older versions of Delphi means missing out on modern enhancements, improved performance, and an easier-to-use IDE.

At GDK Software, we’ve seen firsthand the challenges and rewards of upgrading legacy Delphi projects to the latest versions. That’s why we developed the GDK Duster, a powerful tool designed to simplify and automate the process of converting old Delphi code into modern, maintainable applications. In this post, we’ll dive into how GDK Duster works and how it can help breathe new life into your Delphi projects.

Why updating your Delphi software is essential

We see that there are also many applications that are still being developed on older versions of Delphi. This is a shame, as the newer versions of Delphi really do have many advantages. Not only is the IDE much more pleasant to use, but the new language enhancements are a real improvement.

There are a number of recurring problems when converting old Delphi applications to the latest version of Delphi. For example, starting with Delphi 2009, it is necessary to take Unicode into account. In addition, there may be components that are no longer being developed or have been significantly modified. This means that there are still companies that work with Delphi 5, Delphi 7 or other old versions. Now, converting your source code is not always easy. At GDK Software, we’ve had many projects and customers come to us with older Delphi software. Since we often run into the same problems, we have developed a tool that makes the conversion much easier: the GDK Duster (Delphi Upgrade and Support) tool. In this post, I will briefly explain how GDK Duster helps us with conversion projects and how GDK Software can also help you with upgrading your Delphi project.

GDK Duster

GDK Duster uses the Delphi compiler to automatically compile programs, look for errors, and modify the code to correct those errors. Since all changes are performed via actions, you can simply take the latest code base and restart the conversion every time. During the development of Duster, we always kept in mind to automate the conversion as much as possible.

I will start with a brief introduction to the mechanics of Duster. After that, I will give some examples of the different actions the tool can perform.

Pre-compilation

We perform several steps automatically before starting the compilation process. First, we perform a pre-compile action on the entire source code. This consists of the following actions:

  1. Convert all form files (.dfm files) to text files.
  2. Run all defined preprocessing actions

To start with the first point: with Delphi, it is possible to save form files as binary files. As it is possible to replace components with Duster, form files must be saved as readable text files.

Then we perform all the preprocessing actions. Suppose we know that in each pascal file certain modifications need to be done; we can specify them in the list of actions. Duster will first perform these actions on the whole source code, before starting the actual compilation.

Compilation

Next, we use the tool to compile the project and fix errors.

In order to fix errors, warnings and hints, we create a database of actions that the build helper uses to automatically make changes to the code and recompile the source code. An action can consist of:

  • Add a unit to uses
  • Remove or rename units
  • Modify the code using a simple substitution
  • Modify code using regular expressions
  • Add a prefix to an identifier or variable
  • Change the type of a variable
  • Replace a component (design time)
  • Replace the entire code by performing a substitution or regular expressions in the pascal file.

Examples of actions

As we perform a lot of conversions in the GDK software, we have compiled a fairly extensive list of these actions. With Duster, we can easily add and edit these actions:

Some examples of compiler errors and the corresponding actions are:

error E2003: Undeclared identifier: 'CurrencyString'

The solution is action AddPrefixToIdentifier and the prefix or solution is  FormatSetting.Here, the tool automatically updates the code to FormatSettings.CurrencyString. The same is true for the following errors:

error E2003: Undeclared identifier: 'CurrencyFormat'
error E2003: Undeclared identifier: 'CurrencyDecimals'
error E2003: Undeclared identifier: 'DateSeparator'
error E2003: Undeclared identifier: 'TimeSeparator'
[...enz]

Another example:

error E2003: Undeclared identifier: 'VarArrayOf'

In this case, a unit must be added to the class of uses. This is done using the action AddUnitToInterface where the unit  System.Variants is added.

An example of a more complex action is the solution of the following problem:

error E1050: WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit.

In this example, we have identified Delphi warnings to be displayed as errors. The solution to this problem is the ReplaceByRegEx action. For a replace action (both the regular action and the regular expressions action), we need to specify two parameters: the search string and the result. In this particular case, the search string was a rather complex Regular Expressions function

([\w\^]+[[]?[\w\+\.\-\s]+[]]?)\s+[Ii][Nn]\s+([a-zA-Z0-9[\s]*[Cc][Hh][Rr][(][\d]+[)]*[a-zA-Z0-9'?,\s(\]]*[Cc][Hh][Rr][(][\d]+[)]*[]\)]?)

and the result

CharInSet(\1, \2)

Duster will apply this solution to the specific line of code, after which the compilation process will continue with the rest of the source code.

Adding actions

While working on a conversion, you obviously want to add new actions as easily as possible. Although Duster can solve quite a lot of things automatically, there are always specific problems that need to be solved for a project. That’s why you can easily add your own solutions and actions.

As an illustration I will show an example of a part of the conversion of the (open source) MPEG Audio Collection Library. One of the Delphi projects gives the following error message:

error E2003: Undeclared identifier: 'ReadLn'

The corresponding code line is

Str := TCP.ReadLn;

By analyzing the source code I know that the ReadLn function of the Indy Libraries is now in unit TCP.IOHandler instead of in the unit TCP. So we need the action ReplaceIdentifier and replace TCP. with TCP.IOHandler. Adding this action is now very easy.

The main advantage of modifying your source code in this way is that it is transferrable. If this specific code occurs again somewhere else, Duster will automatically apply this solution there and continue compiling.

As you have seen it is incredibly easy to update existing Delphi projects to the latest Delphi version with the tool. You can also continue the existing development for the old version of the software during the conversion project. Because all changes are stored in actions you can just grab the latest codebase and restart the conversion every time.

How we can help

Modernizing your Delphi application doesn’t have to be a daunting task. With tools like GDK Duster and the expertise of GDK Software, you can easily transition your legacy code to the latest Delphi version, ensuring your application remains functional, secure, and future-proof. Whether you need a personal demo of Duster or expert assistance with your upgrade, we’re here to help. Don’t let your software get stuck in the past—embrace the benefits of modern Delphi development today.

At GDK Software we want to share our knowledge with other developers, and we want to help companies to get and keep their Delphi software up to date. Therefore we have interesting options to use Duster for your software project as well.

Are you interested in a personal demo of Duster, or are you looking for help converting a Delphi project? Please contact me via info@gdksoftware.com

or plan an free online strategy session to see what is possible!

Contact

Let us help you to realise your ambitions

GDK Software UK

(+44) 20 3355 4470

GDK Software USA

+1 (575) 733-5744