Define a trigger block for multiple objects
- Last Updated: May 6, 2024
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Next, you need to define a LEAVE trigger for every field to filter the query
based on what the user entered into that field.
This seems tedious.You should not have to define the same trigger code for every
Customer field, and in fact you do not. First, you need to
learn a little trick about using the trigger code in the Section
Editor. Although the field name the trigger applies to is displayed in a
special drop-down list, you can add more fields to the top of the editable portion of
the window, before the DO keyword, as shown in the following
figure.
To define a trigger block for multiple objects:
- Add the code shown in the above figure.
This code defines the same trigger for all the fields. In ABL syntax, both the event name and the object name can be comma-separated lists.
- Define a variable to hold the query handle and one to hold a
prepare-string:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO. DEFINE VARIABLE cPrepare AS CHARACTER NO-UNDO. - Add the code that walks through the list of field handles, just as the
Filter trigger does, in order to disable them. You need a
variable for a field handle and a variable for a counter:
DEFINE VARIABLE iField AS INTEGER NO-UNDO. DEFINE VARIABLE hField AS HANDLE NO-UNDO.
You may ask whether it would be simpler and more efficient to define these variables
once, in the procedure’s Definitions section, because they are
used locally in both the Filter button trigger and the field
LEAVE trigger. You should not do this. If you do, the leftover
values from one procedure or trigger’s use of the variables remain defined until the
next trigger or procedure uses the variables, increasing the chances that a block of
code will use a stale value by mistake, or that one procedure called from another will
reset the variable that is being used for different purposes by each of them. It is good
practice to scope variables and other objects as locally as possible, even if it means
having the same definitions in more than one place.