Delete Operations in DDOs

A DDO delete is performed by send Request_Delete to a DDO. In some cases, you will use objects such as data-entry object (DEOs) to handle the entire delete for you.  In other cases, you will need to write custom code to perform the delete. In all cases, the delete process itself is the same.

The Request_Delete Message

The Request_Delete message is responsible for deleting a record in the DDO for the main table, updating all parent DDOs (and tables) and possibly deleting all child records.

Two modes of deleting are supported:

 

The property Cascade_Delete_State controls this message.

Deleting a Record and all of its Children

If Cascade_Delete_State is true, Request_Delete will attempt to delete the DDO’s record and all descendant records as follows:

 

Deleting a Record only when no Children Exist

If Cascade_Delete_State is false, Request_Delete will not allow users to delete a record when a child-file record(s) exists as follows:

Deletes when Cascade_Delete_State is false:

 

Handling Errors

If an error occurs anywhere within a delete, the transaction is rolled back, the database is unlocked and the error is reported.

Most often the error will occur within the Validate_Delete event and will be a “controlled” error (i.e., an error purposefully created by the programmer). This must be a real DataFlex error generated using the UserError message or the Error command. The generation of an error is what triggers a transaction rollback. The reporting of the error will be properly deferred until the transaction is rolled back and your database is unlocked.

Although Validate_Delete is the event specifically created to allow you to perform one last validation, you may stop a transaction within any of the delete events (Deleting, Backout, Delete_Main_File, Attach_Main_File, Save_Main_File). If you generate an error, the transaction will be rolled back.