Product Information > JADE Developer’s Reference > Chapter 1 - JADE Language Reference > create Instruction

create Instruction

The create instruction creates an instance of a class, and assigns it to a variable or a property.

Syntax

The syntax of the create instruction is:

create entity [as expression] [transient | persistent | sharedTransient];

The entity value can be a property expression, a local variable, or a formal parameter.

Description

You can optionally specify a class expression in the as clause of the create instruction. The class does not need to be an explicit class name; it can be a variable or any valid expression that yields a class.

The transient, persistent, and sharedTransient modifiers specify whether the instance of the class being created is transient, shared transient, or persistent. If the modifier is omitted, the default lifetime for the class is used.

For details about:

The create instruction on a Form subclass creates a GUI form. If you want to create a print form at run time that simulates the entire GUI process, use the GUIClass class createPrintForm method. (For details, see Chapter 1 of the JADE Encyclopaedia of Classes.)

Examples

The following example shows the use of the create instruction.

createEmployee(newName, newAddress, newPhone: String;
               newBirthDate: Date): Employee;
vars
    newEmployee : Employee;
begin
    create newEmployee;
    newEmployee.name      := newName;
    newEmployee.address   := newAddress;
    newEmployee.phone     := newPhone;
    newEmployee.birthDate := newBirthDate;
    return newEmployee;
end;

The following example shows the use of the as clause in the create instruction.

createFault(faultType: Character): Fault;
vars
    fault : Fault;
begin
    if faultType = "N" then
        create fault as NewFeatureSuggestion;
    elseif faultType = "D" then
        create fault as DocumentationFault;
    else
        create fault f as NormalFault;
    endif;
    ...                        // Do other initialization
    return fault;
end;

The following example shows the use of the create instruction when the class is not an explicit class name.

createFault(faultClass: Class): Fault;
vars
    fault : Fault;
begin
    create fault as faultClass;
    ...                        // Do other initialization
    return fault;
end;