Validate_Delete

The Validate_Delete function is called right before a delete will occur. The participating tables are locked. Generating an error or returning a non-zero value will stop the delete.

A delete operation will delete the main file and all related descendant-file records (child, grandchild, etc.). It does this to prevent orphans. This only occurs if Cascade_Delete_State is true and there is a child-parent relationship between the tables and the DDO structure is proper.

The Validate_Delete is only sent to the DDO in whose main file the delete is being done. If Validate_Delete is approved, the main-file record and all child-file records will be deleted.

If you are prohibiting cascade deletes, it is vital that you forward the Validate_Delete message. The cascade-delete checking occurs as part of this forwarded behavior:

Function Validate_Delete returns Integer

    Integer iError

    Forward get Validate_Delete to iError

    If (Not(iError)) Begin

        If (Customer.status = 'A') Begin

            Send UserError 'Cannot delete active record'

        End

    End

    Function_Return iError

End_Function

The tables of all participating DDOs are locked during Validate_Delete. Therefore, the function should be fast and must never call for user input. The exception to this is the UserError message or the error command. An error generated during the Validate_Delete will be deferred until after the delete has been backed out and the tables have been unlocked.

An error in any of the delete events (Validate_Delete, Deleting, Backout, Delete_Main_File, etc.) starts a transaction rollback. This is a special process. When this happens the remaining code in the function is not executed.

This message is always called in a locked state. Do not perform user input in this event.

If an Error is declared, the transaction will be rolled back. Errors must be generated using the UserError message or the Error command. See Error Handling in Transactions for more information.

When accessing table values you should always access the global file buffers and not the DDO buffers (i.e., use “Move File.Field to var” syntax). See Understanding File Buffers and DDO Field Buffers for more information.

See Also

Defining Data Dictionary Events