The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

Delphi 10.2 Tokyo and up compiler issue: incompatible with Delphi 1.10.1 Berlin behaviour on unit path resolution

Posted by jpluimers on 2021/08/10

There is a very tricky compiler and IDE issue in Delphi 10.2 and up that on the compiler site behaves differently from Delphi 1.10.1 Berlin, and on the IDE side stays the same from Delphi 2005 on.

The issue baffled me, as lot’s features were not added in the Delphi compiler because of backward compatibility reasons.

The problem is that the compiler now favours the unit search path over the paths specified in the .dpr. This breaks compatibility with earlier versions and the IDE: the IDE still thinks pathnames in the .dpr files are the ones to follow.

There are some permutations on this problem, of which a few ones below.

Nonexisting unit in the project, but existing on the search path

  • .dpr file in a directory X
  • a unit inside a different directory A specified the .dpr file, but not on disk, and directory A not in the unit search path
  • a disk version of the unit in yet another directory B where directory B is in the unit search path

This results in Delphi 1..10.1 Berlin to error on compiling the project (because the unit is not found), but 10.2 and up succeeding (because the unit is found).

Existing unit in the project, but directory not on the search a path

Another permutation is this one:

  • .dpr file in a directory X
  • a unit inside a different directory A specified the .dpr file, and on disk, and directory A not in the unit search path

Two same named units, one on search path, other in project but not on search path

Yet another permutation:

  • .dpr file in a directory X
  • a unit inside a different directory A specified the .dpr file, on disk, and directory A not in the unit search path
  • a disk version of the unit in yet another directory B where directory B is in the unit search path
  • unit A and unit B have different content

This works the same in all versions of Delphi: the unit file referenced in the .dpr is compiled.

Via: [WayBack] Jeroen Pluimers on Twitter: “Delphi 10.2 Tokyo and 10.3 Rio compilers break Delphi 1…10.1 Berlin behaviour. Still reproducing and researching the consequences. It for instance means stuff suddenly compiles when it should not, or breaks when it should not. Preliminary reproduction at “

[WayBack] wiert.me / public / delphi / DelphiConsoleProjectWithMissingProjectUnitThatIsOnTheSearchPath · GitLab

–jeroen

Different issue, still on my research list, likely caused by namespace prefixes being handled differently in Delphi 10.2 Tokyo and Delphi 2007..10.1 Berlin:

[WayBack] Jeroen Pluimers on Twitter: “there is a different thing also on my list that gives errors like this “[dcc32 Error] MyUnit.pas(1850): E2242 ‘MyIdentifier’ is not the name of a unit” whereas ctrl-clicking on “MyIdentifier” brings you to the correct place and Delphi 10.1 Berlin not throwing an error.”

[WayBack] Directories/Conditionals: Delphi 2007 project settings

Namespace prefixes
Specifies the prefixes for namespaces, to allow you to create a shorthand version of the namespace in the uses clause in your code file. For example, instead of writing Borland.Vcl.DB, you could specify Borland.Vcl as your namespace prefix. In the uses clause, you could then specify uses DB;.

In my case there was a Data global in DataUnit, reference from UsageUnit as Data.IntegerField, where the error would indicate that IntegerField was not the name of a unit.

This built fine in Delphi 10.1 Berlin, but failed in Delphi 10.2 Tokyo.

–jeroen

Leave a comment

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