Sign in Join
Wiki copytemporary

Delphi Converter in Lazarus

English · 中文(中国)

A Delphi project, Delphi package and a single unit file can be converted for Lazarus. The entries can be found in Lazarus Tools menu:

There is also:

which is seldom needed because the DFM form file is always converted while converting a unit.

Conversions

Here the different conversions are listed briefly. See the sections below for details.

Unit file

Form file

Settings dialog

After selecting an entry from the Tools menu, and then selecting the unit / project / package to convert, the user is presented with a settings dialog. All settings are saved in file delphiconverter.xml in local Lazarus configuration directory. The dialog allows to configure many details of conversion:

Rest of the dialog settings are covered below.

Target

The conversion target is defined in settings dialog. It can be:

However maintaining the file later in both Delphi and Lazarus is problematic because components have slightly different properties.

Unit name replacement and removal

When a unit listed in Uses section is not found, it can be replaced or removed. The replacements are configurable, see "Unit Replacements" in settings dialog. An empty "New name" means removal. For example by default "Windows" is replaced with "LCLIntf, LCLType, LMessages".

The replacement supports regular expression syntax. For example:

means something like: match a string starting with 'Q', followed by anything, and save the part after 'Q', then replace with the saved part. In essence this removes 'Q' in the beginning.

Replacement can be interactive or automatic. When interactive, the user can edit the replacements before they are applied.

If there are still missing units after the replacement, the user will be asked about them in any case. He can then choose to comment them out or search for their unit paths.

Unknown property removal

Not all Delphi component properties are implemented in LCL components. These properties can be removed. There is a system in LCL where non-existent properties are registered and the form loader ignores them. The converter also removes them, automatically or interactively. The interactive removal currently happens in the same dialog that is used for component type replacements (see below). The property can be replaced, too, but that is usually not needed.

Type replacement

Some Delphi components do not exist in LCL. Many 3rd party components also exist only for Delphi. Those types can be replaced with fall-back LCL types. For example:

It is configurable, too, see "Type Replacements" in settings dialog.

The same regular expression syntax as used in unit name replacement is supported here.

The types are replaced in both the Pascal source file and the form file (.lfm). The replacement works also in a nested component structure where a component of replaced type has child components that must also be replaced.

Different properties between the original component and the replacement component can cause problems after conversion. There is no easy solution for this.

The best solution would be to make more Delphi compatible components and port all 3rd party components to Lazarus. Because of these potential problems the type conversion is always interactive.

Function call replacement

Some Windows-only function calls in the source code can be replaced with a functionally similar RTL / LCL library function calls. It is configurable, see "Function Replacements" in settings dialog.

There is a category defined for each function. The replacement can be enabled or disabled by category. For example there is "UTF8Names" category for file operation related functions.

The syntax for replacements is:

where ($1) means the first parameter from the original function call is used for replacement function. There is also a more advanced syntax available. Like this:

ShellExecute can map to 2 different LCL functions. The string after "match" keyword is again a regular expression. If it matches, the replacement right after it is used, otherwise the next replacement.

Coordinate offsets

In Delphi and Lazarus, components have different meaning for Top and Left coordinates when they are inside a visual container. In Delphi the coordinates are relative to container's Top and Left. In Lazarus they are relative to container's client area which leaves out the border. It causes the most visible problem for TGroupBox because it has a title text on the border.

Subtracting an offset from the coordinates makes the form layout look the same as it looked in Delphi. The offsets are defined in "Coordinate offsets" in settings dialog.

Issues

When a Delphi program contains Windows API calls which are not ported in RTL/LCL, there is no automatic way to convert it. Other Windows specific technologies like OLE cause the same problem.

Database connections often require changes. Either the DB or the connection component is not compatible.

Another problem are some libraries which are not compatible with Delphi libraries. For example XML is used in a slightly different way. Maybe the converter can be improved in this area in the future.

As mentioned earlier, Delphi components that don't exist in Lazarus/LCL cause problem, even if they are replaced with a fall-back component type, because they have different properties.

Yet, if the program uses only VCL classes and functions, there is a big chance for the conversion to succeed.


From the Free Pascal wiki, page "Delphi Converter in Lazarus", as it stood on 2024-05-03 after a change by Hieroly, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.