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:
- Delphi language compatibility can be enabled on a file-by-file basis (or even for a sub-portion of a file) using the
$DELPHICOMPATIBILITYCompiler Directive. Possible values are
DEFAULT, with the latter reverting to the project-wide setting.
- 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
- Allow the
dynamickeyword and treat it as identical to
- Allow the
deprecatedkeyword, with messages, and map it to the appropriate
Uses Delphi-style visibility levels for type members:
unit(i.e. visible in the entire file)
unit or protected(i.e. visible to ancestors and in the entire file)
strict privatemeans truly
strict protectedmeans truly
finalizationsections (on some platforms)
class helper forand
record helper forsyntax to declare Extensions
resourcestringto 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
- Allow Nested Types to be declared inside the parent type via
type, instead of Oxygenes
$IFsections, and allow them to be closed by
- 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
withsyntax 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
outin method calls — Allows the passing of by-reference parameters without prefixing them with the
- Allow legacy 'Create' constructors — Allows the use of the
Createname both for declaring and calling Constructors and instantiating new objects. By default, Oxygene uses nameless constructors (and, on Cocoa, optionally constructors with Cocoa's
- 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
/operators to behave as they do on Delphi, with
divalways 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.