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 following Delphi modifier keywords: stdcall, cdecl, pascal
  • Ignore the following Delphi modifier keywords: reference to, register, safecall library, overload, platform.
  • Ignore compiler Delphi directives that have no meaning/use in Oxygene
  • Allow the use of the = operator instead of := in parameter defaults, variable initialization and attributes.
  • Allow Delphi-style GUIDs in interface declaration on .NET and Island to add the [Guid] attribute..
  • Allow otherwise instead of else for case Statements.
  • Allow the dynamic keyword and treat it as identical to virtual.
  • Allow the deprecated keyword, with messages, and map it to the appropriate [Obsolete] attribute.
  • Uses Delphi-style visibility levels for type members:
    • private really means unit (i.e. visible in the entire file)
    • protected really means unit or protected (i.e. visible to ancestors and in the entire file)
    • strict private means truly private
    • strict protected means truly protected
  • Allow initialization and finalization sections (on some platforms)
  • Allow class helper for and record helper for syntax to declare Extensions
  • Allow resourcestring to declare (regular) string constants
  • Allow Delphi's syntax for generic constraints
  • Allow indexed properties
  • Allow using a function's name to assign the function's result
  • Allow Nested Types to be declared inside the parent type via type, instead of Oxygenes nested in syntax.
  • Allow DEFINED() and DECLARED() in $IF sections, and allow them to be closed by $IFEND.

and

  • Enable the four options discussed in the next section.

Other Relevant Project Options

In addition to the "big" Delphi Language Compatibility switch, there are four 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).
  • Allow legacy unscoped enums — Allows enums declared in the current project to be accessed globally, without needing to be prefixed with the enum's type name. Note that this option affects declared enums, not their use. Enums from referenced libraries will still need to be scoped, unless the library was build with this option on, and enums declared in a library with the option on will show as globals in all projects that reference the library, regardless of whether the option is turned on in the referencign project.
  • 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.

See Project Settings Reference: Delphi Compatibility Build Settings. Turning on Delphi Language Compatibility option discussed above will implicitly enable these four option as well.

See Also