User Tools

Site Tools


standardcontrolhandling_group.htm
Navigation:  Templates > Template Language Reference > Annotated Examples > Procedure Template: Window >====== %StandardControlHandling #GROUP C6H0068.jpg ====== Previous pageReturn to chapter overviewNext page

This #GROUP generates all the code to handle field-specific events for the procedure. It generates its code inside the Window template's CASE FIELD() structure.

#GROUP(%StandardControlHandling)

#FOR(%Control),WHERE(%Control)

 #MESSAGE('Control Handling: ' & %Control,3)

 #SUSPEND

#?OF %Control

 #EMBED(%ControlPreEventCaseHandling,'Control Handling, before event handling') %|

       ,%Control

 #?CASE EVENT()

   #IF(NOT %ControlMenu)

     #FOR(%ControlEvent)

       #SUSPEND

 #?OF EVENT:%ControlEvent

   #EMBED(%ControlPreEventHandling,'Control Event Handling, Before Generated Code') %|

         ,%Control,%ControlEvent

   #INSERT(%FieldTemplateStandardHandling)

   #EMBED(%ControlEventHandling,'Internal Control Event Handling') %|

         ,%Control,%ControlEvent,HIDE

   #EMBED(%ControlPostEventHandling,'Control Event Handling, After Generated Code') %|

         ,%Control,%ControlEvent

       #RESUME

     #ENDFOR

   #ELSE

 #?OF EVENT:Accepted

   #ENDIF

   #SUSPEND

 #?ELSE

   #EMBED(%ControlOtherEventHandling,'Other Control Event Handling'),%Control

 #RESUME

 #?END

 #EMBED(%ControlPostEventCaseHandling,'Control Handling, after event handling') %|

       ,%Control

 #RESUME

#ENDFOR

This code starts with the #FOR(%Control),WHERE(%Control) statement. The WHERE clause may at first seem redundant, since #FOR will only loop through existing instances of %Control. However, since some controls do not need (and so do not have) field equate labels, there are valid instances of %Control that do not contain a value for %Control itself. Therefore, the WHERE attribute limits this #FOR loop to those instances of %Control that do contain a field equate label for the control.

The #MESSAGE statement displays its message during source generation. #SUSPEND begins a conditional source generation section.

The #?OF %Control statement conditionally generates an OF clause to the CASE FIELD() structure for the currently processing instance of %Control. This line of code, since it is prefaced with #?, will only generate if there is some other code generated within it, eliminating an empty OF clause.

The first #EMBED allows the programmer to handle any situation that needs to be handled before any generated code for the control. The #?CASE EVENT() conditionally generates a CASE EVENT() structure for the control. The #IF(NOT %ControlMenu) statement filters out all the menu items, since they are handled by the %StandardAcceptedHandling #GROUP. #FOR(%ControlEvent) loops through all the possible events that the control being processed can generate.

#SUSPEND begins another conditional source generation section, nested within the previous one. This allows multiple levels of conditional source code generation. The outer section is automatically generated if any code is generated from the inner section.

The #?OF EVENT:%ControlEvent statement conditionally generates an OF clause to the CASE EVENT() structure for the currently processing instance of %Control. This line of code, since it is prefaced with #?, will only generate if there is some other code generated within it, eliminating an empty OF clause.

This next #EMBED statement has “,%Control,%ControlEvent” appended to the end, so the programmer will have a separate embed point available for every instance of the %ControlEvent symbol within every instance of the %Control symbol. This means programmers can write their own code for any field-specific event, for any control . It also means any Code templates, Control templates, or Extension templates the programmer places in the procedure can generate code into these embed points, as needed, to produce the code necessary to support their functionality. These embed points are the targets of the #AT statements used in the Code, Control, and Extension templates.

The #INSERT(%FieldTemplateStandardHandling) statement generates code to handle all the Actions tab selections the programmer has made for the control. The prompts on the Actions tab come from the #FIELD structures that were #INSERTed at the beginning of the Window template.

The next two #EMBED statements also have “,%Control,%ControlEvent” appended to the end, so the programmer will have a separate embed point available for every instance of the %ControlEvent symbol within every instance of the %Control symbol. The first has the HIDE attribute, so it is available only for Code, Control, and Extension template use. These three #EMBEDs give the programmer an embed point both before and after any code automatically generated for them by the Actions tab prompts.

#RESUME terminates the inner conditional source generation section, then #ENDFOR terminates the %ControlEvent loop. The #ELSE refers back to the #IF(NOT %ControlMenu) and will generate an empty OF EVENT:Accepted followed by an ELSE statement for a Menu item if the programmer has entered code into the Other Control Event Handling embed point. This eliminates any duplication between EVENT:Accepted code for a menu item while still allowing the programmer to process any user-defined events for them.

The #SUSPEND statement begins another nested conditional generation section. This means the #?ELSE statement only generates an ELSE if source code is generated by the #EMBED statement. #RESUME terminates this #SUSPEND section.

The #?END generates the END statement for the CASE FIELD() structure, if any code has been generated, then the #RESUME statement terminates the outer #SUSPEND section. #ENDFOR terminates the %Control loop.

standardcontrolhandling_group.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1