Defining Data Dictionary Events
Part of the Data Dictionaries class creation process is the defining of custom behaviors in events. These events allow you to customize the main Data Dictionary processes. Those processes are: Find, Clear, Save, and Delete.
Events are provided to allow you to control the following:
- Perform validations and error checking during a save or a delete. If an error is generated, the save or delete is canceled and any changes are rolled back.
- Maintain balances between related tables during saves and deletes.
- Define and control special relationships between tables.
- Perform special processing when new records are found, including setting default values for new records.
- Execute special save or delete processing.
A single event may be used by multiple operations. For example, the Backout event is called during a save and a delete. The Relate_Main_File event may be called by saves, deletes, finds, and clears.
Some events are always called in a locked state (e.g., Update and Backout), while other events may be called in an unlocked state (e.g., Relate_Main_File).
The predefined Data Dictionary events are:
- Attach_Main_File
- Backout
- Clear_Main_File
- Creating
- Delete_Main_File
- Deleting
- Field_Defaults
- OnNewCurrentRecord
- Relate_Main_File
- Save_Main_File
- Update
- Validate_Delete
- Validate_Save
Forward Sending Event Messages
You should always forward event messages.
Although some of the Data Dictionary events perform no default action, other events perform very important tasks and must be forwarded. Unless you specifically want to cancel a behavior, you are advised to always forward your event augmentations. This creates code that is robust – it will work the first time and it will continue to work as changes are made to your underlying classes.
For example, while we could code an event as follows:
// incorrect
Procedure Update
Move (Customer.due + order.total) to Customer.due
End_Procedure
We will instead code this with a forward send:
// correct
Procedure Update
Forward send Update
Move (Customer.due + order.total) to Customer.due
End_Procedure
User Defined Field Events
Data Dictionaries allow you to define events that should be called when a field is validated and when windows data-entry objects bound to a particular field are entered or exited. These events are tied to fields using the Field_Validate_msg, Field_Entry_msg, and Field_Exit_msg and are discussed in their own sections. In particular, the field validation events can be particularly useful.