Creating Objects

The New operator is used to create class instances. A basic class name, a constructor name, and a parameter list should follow after the New word. Operation result is a reference to a newly created object.

Class TestObject: Object
    _a: Integer;
    
    
Public Constructor Create(a: Integer = 0);
    
Begin
        _a := a;
    
End Constructor Create;
End Class TestObject;

Sub Main;
Var
    obj: TestObject;
Begin
    obj := 
New TestObject.Create;
    obj := 
New TestObject.Create(100);
End Sub Main;

The New operator is not required for classes that present the data types Boolean, Char, Currency, DateTime, Decimal, Double, Integer, TimeSpan, Variant, String. These types of variables are not references to objects but to objects themselves. Thus, the assignment operation looks as follows:

Sub Main;
Var
    a: Integer;
Begin
    a := 
100;
End Sub Main;

See also:

Classes and Objects