How Do I Utilize the Event Hierarchy? (Magic xpa 3.x)
One of the issues to think about with events is, who will handle the event? That is, when an event is raised, there may be several levels of tasks that could handle it. One good example of this would be a DBMS error. If the DBMS raises an error, you may want to give the user an error message for some types of errors. However, you may also want to have a global error tracking program that logs all DBMS errors to a database for reporting.
You also might want to override, say, a keystroke. For instance, F3 is by default mapped to delete line, and it will automatically delete the current record from the DB table. But you might want to trap F3 and just mark the record deleted instead. Or you might want to trap F3, delete some related records in your logic unit, and then have Magic xpa delete the current record.
This is all done using the Propagate flag. If propagate is set to Yes, then the logic unit executes, and passes the event up to the next level. If propagate is set to No, then the logic unit executes, and the event is blocked.
Magic xpa uses a specific search order to determine the logic hierarchy. It executes events that are tied to a specific control first, then the events that are not tied to any controls. It proceeds up the task tree, up to the Main Program. Lastly, Magic xpa handles the event, if it is not blocked.
Let’s take a specific example.
Here you have an event that totally blocks F3. If the user presses F3, that will trigger this event. But the event does not propagate, so Magic xpa will not handle it, and will not delete the record.
This logic unit executes a call to a subtask to delete some related records. Then it passes the F3 system event to Magic xpa, which will delete the current record.
Hint: Though this example shows how to block a keystroke, it is usually better to intercept an action like delete line at the internal event level, because the user can also use the menu options to delete a line, or the keyboard may be re-mapped, or the delete line event may be raised by the program itself, in a push button for example. You can see how to intercept the delete line event in Blocking an internal event.
The Online and Rich Client Samples projects (program EN02 and REN02)