New Expressions

new can be used to instantiate a class or an array type. When instantiating a class use parenthesis, when instantiating an array type use blocks.

// creates a new instance of List<String> and calls the constructor.
var x := new List<String>;

// creates an array of integers with size 15
var y := new int[15];

Named parameters

When calling constructors the parameters are matched to a constructor on the class, any named parameters are matched to fields or properties on the class:

  MyClass = public class
    constructor(aParam: Integer);

    property Field: String;

var x := new MyClass(15, Field := 'Hello');
// Calls the constructor with 15, then sets Field to 'Hello'.

Extended Constructor Calls

Very often the first task after creating a class instance is to initialize some of its properties that are not set by a constructor. For example:

var b := new Button();
b.Title := 'Click me!';

Oxygene allows you to add named parameters after the normal constructor parameters in order to fill properties on the constructed object. These are in the form of name := value pairs. Thus, the code above can be written like this:

var b := new Button(Title := 'Click me!');

This extended syntax is only supported for constructors, and the named parameters must be placed after any of the regular constructor parameters.