Namespace compatibility in VCL for Delphi
Asked Answered
L

1

6

How can I best maintain compatibility for namespaces in uses between Delphi 7 to Delphi XE7 ?

Delphi 7 use SysUtils while Delphi XE7 use System.SysUtils.

It clutter the code a lot with many ifdefs, so I want to avoid it if possible.

Lancashire answered 22/3, 2015 at 17:11 Comment(1)
You are right. I have access to XE6, but want to support D7 and forward.Lancashire
I
9

In the later versions of Delphi which support namespace prefixes (I believe that's XE2 and up), you can define the namespaces in the project options.

Project Options > Delphi Compiler > Unit scope names

Then, you won't need to include those prefixes in your uses clause.

By default, new projects will automatically include most of these for you. However if you're upgrading an old project, especially a package, these might not be populated by default. I've had an incident where randomly Delphi started failing to compile because these units were missing their namespace prefixes.

Imposing answered 22/3, 2015 at 17:14 Comment(3)
I don't think that was random. The answer is right tho!!Vambrace
@David Well it appeared out of nowhere, not even making any changes that could trigger that to happen. "Appears to be random" at least.Imposing
What will have happened will be that you defined unit scope names in one config and switched to another. This part of the ide and compiler is rock solid.Vambrace

© 2022 - 2024 — McMap. All rights reserved.