Replacing default trigger code

Tony Marston - 16th March 2001

Why would you want to change default trigger code?

By default the <on error> triggers are empty apart from some comment lines. This does not mean that no code is executed because the default code is contained within the UNIFACE kernel. The only problem is that if you get the message "0129 - subfields are required" you cannot step through in debug to see which field trigger generated the message because an empty trigger is never fired and its name will not appear in any debug or trace lists. One solution would be to replace the standard text for message 0129 to include a reference to $fieldname. Another would be to put some code in the trigger using one of the procedures described below.

Changing trigger code for existing entities and fields

It is possible to amend trigger code within individual components, but this is a laborious process if the same amendment is required every time. It is also impossible to amend trigger code for fields which are not painted. It is also possible to perform a global update, either on components or the application model, but this is an additional step which may be forgotten. It would be a lot easier if the desired code were to be inserted into the triggers when they are first created, thus removing the need for a subsequent amendment.

Where does the initial trigger code come from?

When entities and fields are created, either in the application model or within components, the initial procedure code for their triggers is automatically loaded from system defaults which are obtained from entries in the message file (library=USYS, language=USA). It is possible to replace these message file entries with versions of your own so that code of your choosing is used instead. The names of the entries associated with each trigger are provided in Chapter 4 of the Proc language Reference Manual (Triggers), but some of the most common ones are as follows:

Trigger Name Message File Name
accept ACCEPTDEF
add/insert occurrence ADDINSOCC
clear CLEARDEF
delete DELETEDEF
erase ERASEDEF
help GHELPDEF
leave modified key LEAVEMODKEY
on error (entity) ONERRORENT
on error (field) ONERRORFLD
remove occurrence REMOVEOCC
validate key VLDKDEF

How to define your own initial trigger code

Like any message file entry it is possible to override the default either by replacing the original in the USYS library (not recommended) or by creating an alternative in a different library and forcing UNIFACE to look there first. To use an entry from your own application library you must update your assignment file as follows:

It will also be necessary to set these values for default project library and default project language in your developer preferences within the IDF.

When defining new default trigger code it would be better to reference a global proc rather than defining the code in long hand. In this way it would be possible to make global changes to individual procs rather than multiple triggers in multiple components.

For more details on this subject please refer to Appendix C of the Proc Language Reference Manual (Default Proc Code for Triggers).


Tony Marston
16th March 2001

mailto:tony@tonymarston.net
mailto:TonyMarston@hotmail.com
http://www.tonymarston.net

counter