Module_EventHandling

Type: Module Parent Module: N/A

This module converts OMNIS 7 event handling which uses $v3events to the OMNIS Studio paradigm. For example "If #AFTER" is converted to "On evAfter" etc. We will attempt to resolve certain configurations like "If #AFTER&NOT(#CANCEL)" but some that cannot be easily restructured will be logged as user fix errors.

Functionality

This module only processes field and window $event methods. When one of these is encountered then the method code is searched for occurences of the OMNIS 7^3 event messages #AFTER, #BEFORE, #CLICK etc.

If the command which contains the message is not an "If", then this is logged as a user fix error.

If the message variable is located in a field $event method:

  1. If the command only contains 1 message variable then "If..." or "Else If..." is converted to "On ev..."
  2. Certain values of #ER will also be converted to the Studio equivalent (e.g. "If #ER=7" to On evCancel").
  3. If the command only contains several message variables separated by | (or) then "If #X|#Y" or "Else If #X|#Y" is converted to "On evX,evY".
  4. Other than certain straightforward combinations, If the command contains several event message variables separated by & (and) then this is logged as a user fix error.
  5. If the command contains an event message variable and other non-event message variables (e.g. fv_myvar, #D, #CT, #EDATA etc.) separated by & (and) then the event message part is converted to "On ev..." and the rest of the expression is moved to a new "If..." statement on the next line terminated with a corresponding "End If" statement inserted in the approropriate position in the method.

In cases where an "If..." command is replaced by "On ev...", the matching "End if" command is removed.

For example: If #AFTER
is converted to: On evAfter
and: If #AFTER|#CLICK
is converted to: On evAfter,evClick
and: Else If #BEFORE
is converted to: On evBefore
and: If (#AFTER|#CLICK)&x=y
is converted to: On evBefore,evClick
If x=y ;; this part is moved to the following line
and: If AFTER&#CLICK|x=y
is not converted

If the message variable is located in a window $event method:

If the code is not an "If..." or or "Else If...", then a user fix error is logged.

Certain message variables are preprocessed to convert to use Studio pNextCode parameter.

  1. not(#CANCEL) to pNextCode<>evCancel
  2. #CANCEL to pNextCode=evCancel
  3. not(#OK) to pNextCode<>evOK
  4. #OK to pNextCode=evOK

Then the module needs to figure out whether the event in question is a field or window level event.

  1. This is done using the value of the message variable (e.g. #AFTER, #WCLICK etc.)
  2. If the event in question is a field level event (i.e. #AFTER, #BEFORE, #CLICK etc.) then the related code is moved to the window $control method and converted to OMNIS Studio event paradigm as described above.
  3. If the event in question is a window level event (i.e. #CANCEL, #OK, #TOTOP, #WCLICK etc.) then the related code is moved to the window $event method and converted to OMNIS Studio event paradigm as described above.
  4. If the old window control method is empty following this processing then delete it.

Note that this approach may lead to problems if a field event handler calls another method of the window class to detect field level events. For example the called procedure may contain "If #CLICK...some code...End if" commands, containing some code to deal with the click. In this case since #CLICK is a field level event, the code will be moved to the $control method and the processing will be applied to all fields on the window rather than just the originally intended field. This situation should be remedied in the OMNIS 7 code by moving the code that detects the event to the field procedure. So for the example above the "If #CLICK" and "End if" should be moved to the field procedure, and the "some code" bit left in the called procedure.

If more than 1 class method has code that detects events, then a warning that there is more than 1 Window Control Method in the class is displayed in the log.

Lines containing "SNA..." commands are converted to an appropriate "Queue..." event command and a "Quit event handler (Discard event)" command added to the next line. If there is no equivalent Studio command then a user fix error is logged.

When processing a "SNA set current field" command the method $lookUpObjName is used to convert the dataname or field number from the original command to the object name.

Lines containing "Set window control method OBSOLETE COMMAND" are removed.

Lines containing "Set task control method OBSOLETE COMMAND" or "sys(84)" function are logged as user fix errors.

If while processing an event block any nested checks for the same event are located (e.g. "If #CLICK" inside another "If #CLICK") then this is converted to test "pEventCode" instead (e.g. "If pEventCode=evClick" inside "On evClick").

Any duplicate "Quit event handler (Discard event)" (i.e. one immediately followed by another) or "Quit method" following "Quit event handler (Discard event)" are removed.

Any commands that follow a "Quit event handler" command are moved so that they precede the "Quit event handler" if possible. This is done because those commands would not otherwise ever be executed. This is not applied to commands that occur outside of the code block. If an "End if" or other command that delimits a code block is encountered following a "Quit event handler" command, then it is not moved since this would affect the logic flow.

The library property $prefs.$v3events is set to kFalse so that only the Studio event behaviour in enabled.

Other Considerations

The following issues are not currently dealt with:

  1. May need to deal with "Do not pass event", "Quit to enter data commands". Probably only require removing from method.
  2. If field level events are being handled at field and window level we should add "Quit event handler (Pass to next handler)" to field level $event methods to force the event up to the window.

Assumptions

  1. Each window has only 1 Window Control Procedure and this is located in a method inside the window class.
  2. A particular event (e.g. #CLICK) is not required to be handled by the field event handler and by the Window Control Procedure.
  3. A class method that checks for an event (e.g. using "If #CLICK") is the Window Control Procedure. If a field event handler calls a method that then checks for an event, then this will be incorrectly interpretted as being part of the Window Control Procedure and therefore the code will be copied to either the $event or $control method of the window class.
  4. "SNA set current field" commands reference objects within the window class being processed.

User Setup Required for this Module

  1. None.