Delphi

Island/Delphi mode in Elements (currently experimental) allows the use of Delphi-built types and APIs, compiled into one or more Delphi packages, from your Island projects on desktop Windows, Linux and macOS. The "Delphi" object model is provided to enable using and implementing classes based on Delphi's TObject class hierarchy.

  • Island – native Island objects and interfaces.
  • Cocoa –Objective-C objects (descending from Foundation.NSObject) and protocols.
  • Delphi – Delphi objects (descending from Delphi.System.TObject) and protocols.
  • COM – to work with COM interfaces
  • Swift – native Swift objects and protocols.

Delphi support is limited to platforms and architectures your particular version of Delphi supports, and will for now not extend to mobile platforms. Please refer to the Delphi Platform topic for more details.

Several prerequisites, described under the link above, are required to use the "Delphi" object model, most importantly a reference to an imported Delphi SDK.

Delphi classes share a single hierarchy, rooted in Delphi.System.TObject.

Life-Cycle Management

Just like in Delphi itself, "Delphi" object model classes do not receive any automatic life cycle management – meaning user code must manually track their use and release them when needed by calling Free, FreeAndNil, the Destroy destructor, or other appropriate APIs.

Please refer to the Delphi documentation for more details on life-cycle managemernt of Delphi objects.

Default Types

When set as Default Object Model, the following three base types come into scope to be used for Objects,, Strings and Exceptions (and for the C# object and string keywords):

  RemObjects.Elements.System.Delphi.Object = public DelphiObject;
  RemObjects.Elements.System.Delphi.String = public DelphiString;
  RemObjects.Elements.System.Delphi.Exception = public DelphiException;

These again alias directly to the base types provided by Delphi:

  DelphiObject = public Delphi.System.TObject;
  DelphiChar = public {$IF ANSI_STRING}Delphi.System.AnsiChar{$ELSE}Delphi.System.WideChar{$ENDIF};
  DelphiString = public {$IF ANSI_STRING}Delphi.System.AnsiString{$ELSE}Delphi.System.UnicodeString{$ENDIF};
  DelphiException = public Delphi.System.SysUtils.Exception;

Note that depending on the Delphi version used, DelphiString will be 8-bit Ansi or 16-bit Unicode. In both cases it will be a reference-counted string with internal copy-on-write semantics, and of course compatible with all Delphi String APIs.

DelphiString will seamlessly cast from and to Island's native string type and (on the macOS platform) to NSString and Swift.String.

Like in Delphi, DelphiStrings are a non-class data structure, and not part of the TObject class hierarchy, but they will be assignable to Island-model Objects (and seamlessly cast to a native Island String, for that purpose).

Read more about Delphi String Support.

Wrapping

Note that Delphi types will get wrapped when assigned to an (Island-model) Object variable or parameter, just as native Island types will get wrapped when passed to a TObject type variable or parameter. This is necessary because the two hierarchies do not share a common ancestor.

Basic operations such as checking for equality or a type's hash will work for two wrapped instances, and of corse wrapped objects can be cast back to a concrete type.

See Also