Constructor Call
Inside a Constructor, the constructor
keyword can be used to defer construction of a Class or Record instance to another constructor on the same type, or the ancestor class.
Used on its own, the constructor
keyword calls a different constructor on the same type:
type
MyClass = public class
public
constructor;
constructor(aName: String);
property Name: String;
end;
constructor MyClass;
begin
constructor('My Name'); // calls the second constructor.
end;
constructor(aName: String);
begin
Name := aName;
end;
Please refer to the Constructors: Deferred Construction topic for more details.
Constructor calls accept parameters, and they can also work with named and multi-part constructors. Just as in new
Expressions, the keyword can be followed (optionally) by a name, and/or a set of parameters. Unlike new
Expressions, constructor calls can not take additional properties to initialize, but that can be done as separate statements after the constructor call.
'inherited` Constructor Calls
In constructors for Classes, the inherited
Expression can be used with constructor
calls in order to defer execution to a constructor of the base class:
constructor;
begin
DoSomeWork();
inherited constructor("Hello");
DoSomeMoreWork();
end;
'mapped` Constructor Calls
In Mapped Types, constructors can defer defer to constructors of the original type using the mapped
Expression with the constructor
call:
constructor;
begin
mapped constructor("Hello");
DoSomeAdditionalSetup();
end;
Please refer to the Mapped Types: Constructors sub-topic for more details.
See Also
- Constructors and Deferred Construction
- Mapped Types
- Classes
inherited
Expressionmapped
Expression