delete Instruction

The delete instruction deletes an object.

Syntax

The syntax of the delete instruction is:

delete expression;

The expression value evaluates to an object reference.

Description

The action of the delete instruction is first to evaluate the expression and then to attempt to delete the object that the expression references.

If the referenced object exists, it is deleted. If the object does not exist, an exception is raised, but no exception is raised if the reference is null.

The value of a deleted local variable or property is set to null by the delete instruction, so that the deleted object cannot be inadvertently accessed at some later stage.

The operand of a delete instruction must be capable of being assigned to. For example, an error is reported if you attempted to delete a usage input parameter. The parameter would have to be made usage io or output for the code to compile without error.

For details about the RootSchema classes for which you can delete persistent instances, see "Instructions for Creating and Deleting Objects", earlier in this chapter.

Example

The following example uses the delete instruction to clear an array.

removeGraph(graphName: String) updating;
vars
    graph : Object;
    count : Integer;
begin
    // because the graph has been stopped, we must remove all
    // data that is used to create the graph
    count := 1;
    while count <= myLines.size do
        graph := myLines[count];
        if graph.IGLines.name = graphName then
            self.myLines.removeAt(count);
            delete graph.IGLines;
            count := count - 1;
        endif;
        count := count + 1;
    endwhile;
end;