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:
Shared transient transactions, see "beginTransientTransaction", earlier in this chapter. See also "Sharing Uncommitted Persistent Objects".
For details about the RootSchema classes for which you can create persistent instances, see "Instructions for Creating and Deleting Objects".
The create instruction on a
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;