This year (2020), Delphi celebrates its 25th anniversary. In those 25 years, a huge amount of code has been written. Many of these applications are still in full use by companies and individuals. This shows the power of Delphi; code written decades ago still works, even in the latest versions of Delphi.
Still, there are some observations to be made about this accolade. Unfortunately, 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 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.
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:
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.
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:
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'
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
and the result
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.
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.
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 firstname.lastname@example.org