inheritCreate Instruction

The inheritCreate instruction invokes the superclass constructor with parameters implementation of a method.

Syntax

The syntax of the inheritCreate instruction is:

inheritCreate (parameters);

Description

When a subclass reimplements a method defined in a superclass, you can use the inheritCreate instruction from a subclass method to cause execution of the superclass method.

Superclass constructors with parameters are called explicitly from the constructor of any immediate subclasses, using the inheritCreate instruction.

It is recommended that inheritCreate is the first instruction in the method. However, this is not enforced because it is trivial to write code that executes against a partially constructed object; for example, by using the result of a method call as the value to a parameter to a superclass constructor.

If the superclass constructor has parameters, the compiler will verify that the call to the constructor is coded and that the parameters are correct. If the superclass constructor does not have parameters, an explicit call is not allowed.

In the following hierarchy, when an instance of B is created, A::create is called, then B::create is called with the parameters provided in the create instruction. When an instance of C is created, A::create is called, then C::create. B::create must be called explicitly by C::create.

// class hierarchy
A - create() // explicit
  \
    B - create(i:Integer) // explicit
      \
        C - create() // explicit
A::create();
begin
end;
B::create(i: Integer);
begin
    // must not call A::create();
end;
C::create();
begin
    // must call B::create();
    inheritCreate(123);
end;

Example

The following method indicates whether the superclass constructor has been called (it should not have been).

create() updating;
begin
    createC71 := createC7;
    inheritCreate("football");
end;

The following method is an example of the inheritCreate instruction.

create() updating;
begin inheritCreate("123"); inheritCreate("456"); end;

See also the inheritMethod instruction.