Delphi Compatibility Settings

Aside from the vast amount of new features that Oxygene brings to Object Pascal, it also provides some to make the language more consistent and a better citizen on the (semi-)managed platforms.

We believe that these changes, as small and as trivial as some of them seem to be, are an important factor of what makes the Oxygene language clean and consistent, and we encourage developers to embrace them, rather than resists change and disable them — but we also realize that there is a need for developers to share some code between Oxygene and Delphi and maintain it for both compilers.

And so we have provided a compiler option to enable enhanced Delphi compatibility — at the expense of making the language a bit more cluttered and inconsistent when this option is enabled.

There are two ways to enable this mode:

  1. Delphi language compatibility can be enabled on a file-by-file basis (or even for a sub-portion of a file) using the $DELPHICOMPATIBILITY Compiler Directive. Possible values are ON, OFF and DEFAULT, with the latter reverting to the project-wide setting.
  2. It can also be enabled for the entire project in the Compatibility section of Project Settings.

Effects of the Delphi Language Compatibility option

Turning on Delphi language compatibility effects the following changes in the Oxygene compiler:

  • Allow the use of the = operator instead of := in parameter defaults, variable initialization and attributes.
  • Allow Delphi-style GUIDs in interface declaration on .NET to add the [Guid] attribute..
  • Ignore the following Delphi keywords: reference to, stdcall, cdecl, pascal, register, safecall, overload, library, static, platform.
  • Allow the dynamic keyword and treat it as identical to virtual.
  • Allow the deprecated keyword and map it to the appropriate [Obsolete] attribute.
  • Allow the use of strict to prefix private and protected visibility sections. The two keywords will merely be ignored, since Oxygene's private and protected visibility already behave properly to start with.

Other Relevant Project Options

In addition to the "big" Delphi Language Compatibility switch, there are three more compatibility options (available on the same Project properties tab) that might be relevant to Delphi developers:

  • Allow legacy 'with' — Restores Delphi's unsafe with syntax that does not require an explicit variable declaration, like Oxygene's keyword does. We highly discourage enabling this option, and recommend revising the Delphi code in question instead, if you must share code between Delphi and Oxygene.
  • Allow implicit var/out' in method calls — Allows the passing of by-reference parameters without prefixing them with the var or out keyword.
  • Allow legacy 'Create' constructors — Allows the use of the Create name both for declaring and calling Constructors and instantiating new objects. By default, Oxygene uses nameless constructors (and, on Cocoa, optionally constructors with Cocoa's with* naming convention).
  • Use Delphi-compatible division operators — Changes the div and / operators to behave as they do on Delphi, with div always producing an integer result, and / always producing a float result, regardless of input.

Read More

Read more about the language differences between Oxygene and Delphi: