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

This #GROUP actually generates all the source code for the Window template. This includes all the local data declarations, standard window handling code, and provides all the “hooks” for all the control and extension templates to attach into the generated procedure.

#GROUP(%StandardWindowCode)

#IF(NOT %Window)

 #ERROR(%Procedure & ' Error: No Window Defined!')

 #RETURN

#ENDIF

#DECLARE(%FirstField)

#DECLARE(%LastField)

#DECLARE(%ProgressWindowRequired)

#INSERT(%FieldTemplateStandardButtonMenuPrompt)

#INSERT(%FieldTemplateStandardEntryPrompt)

#INSERT(%FieldTemplateStandardCheckBoxPrompt)

#EMBED(%GatherSymbols,'Gather Template Symbols'),HIDE

#INSERT(%FileControlInitialize)

%Procedure %ProcedureType%Parameters

#FOR(%LocalData)

%[20]LocalData %LocalDataStatement

#ENDFOR

#INSERT(%StandardWindowGeneration)

#IF(%ProgressWindowRequired)

#INSERT(%StandardProgressWindow)

#ENDIF

 CODE

 PUSHBIND

 #EMBED(%ProcedureInitialize,'Initialize the Procedure')

 LocalRequest = GlobalRequest

 OriginalRequest = GlobalRequest

 LocalResponse = RequestCancelled

 ForceRefresh = False

 CLEAR(GlobalRequest)

 CLEAR(GlobalResponse)

 #EMBED(%ProcedureSetup,'Procedure Setup')

 IF KEYCODE() = MouseRight

   SETKEYCODE(0)

 END

 #INSERT(%StandardFormula,'Procedure Setup')

 #INSERT(%FileControlOpen)

 #INSERT(%StandardWindowOpening)

 #EMBED(%PrepareAlerts,'Preparing Window Alerts')

 #EMBED(%BeforeAccept,'Preparing to Process the Window')

 #MESSAGE('Accept Handling',3)

 ACCEPT

   #EMBED(%AcceptLoopBeforeEventHandling,'Accept Loop, Before CASE EVENT() handling')

   CASE EVENT()

   #EMBED(%EventCaseBeforeGenerated,'CASE EVENT() structure, before generated code')

   #INSERT(%StandardWindowHandling)

   #EMBED(%EventCaseAfterGenerated,'CASE EVENT() structure, after generated code')

   END

   #EMBED(%AcceptLoopAfterEventHandling,'Accept Loop, After CASE EVENT() handling')

   #SUSPEND

   #?CASE ACCEPTED()

   #INSERT(%StandardAcceptedHandling)

   #?END

   #RESUME

   #EMBED(%AcceptLoopBeforeFieldHandling,'Accept Loop, Before CASE FIELD() handling')

   #SUSPEND

   #?CASE FIELD()

   #EMBED(%FieldCaseBeforeGenerated,'CASE FIELD() structure, before generated code')

   #INSERT(%StandardControlHandling)

   #EMBED(%FieldCaseAfterGenerated,'CASE FIELD() structure, after generated code')

   #?END

   #RESUME

   #EMBED(%AcceptLoopAfterFieldHandling,'Accept Loop, After CASE FIELD() handling')

 END

 DO ProcedureReturn

!—————————————————————————

ProcedureReturn ROUTINE

!|

!| This routine provides a common procedure exit point for all template

!| generated procedures.

!|

!| First, all of the files opened by this procedure are closed.

!|

!| Next, if it was opened by this procedure, the window is closed.

!|

!| Next, GlobalResponse is assigned a value to signal the calling procedure

!| what happened in this procedure.

!|

!| Next, we replace the BINDings that were in place when the procedure initialized

!| (and saved with PUSHBIND) using POPBIND.

!|

#IF(%ReturnValue)

!| Finally, we return to the calling procedure, passing %ReturnValue back.

#ELSE

!| Finally, we return to the calling procedure.

#ENDIF

!|

 #INSERT(%FileControlClose)

 #INSERT(%StandardWindowClosing)

 #EMBED(%EndOfProcedure,'End of Procedure')

 #INSERT(%StandardFormula,'Procedure Exit')

 IF LocalResponse

   GlobalResponse = LocalResponse

 ELSE

   GlobalResponse = RequestCancelled

 END

 POPBIND

 #IF(%ProcedureType='FUNCTION')

 RETURN(%ReturnValue)

 #ELSE

 RETURN

 #ENDIF

!—————————————————————————

InitializeWindow ROUTINE

!|

!| This routine is used to prepare any control templates for use. It should be called

!| once per procedure.

!|

 #EMBED(%WindowInitializationCode,'Window Initialization Code')

 DO RefreshWindow

!—————————————————————————

RefreshWindow ROUTINE

!|

!| This routine is used to keep all displays and control templates current.

!|

 IF %Window{Prop:AcceptAll} THEN EXIT.

 #EMBED(%RefreshWindowBeforeLookup,'Refresh Window routine, before lookups')

 #INSERT(%StandardFormula,'Before Lookups')

 #INSERT(%StandardSecondaryLookups)

 #INSERT(%StandardFormula,'After Lookups')

 #EMBED(%RefreshWindowAfterLookup,'Refresh Window routine, after lookups')

 #EMBED(%RefreshWindowBeforeDisplay,'Refresh Window routine, before DISPLAY()')

 DISPLAY()

 ForceRefresh = False

!—————————————————————————

SyncWindow ROUTINE

 #EMBED(%SyncWindowBeforeLookup,'Sync Record routine, before lookups')

 #INSERT(%StandardFormula,'Before Lookups')

 #INSERT(%StandardSecondaryLookups)

 #INSERT(%StandardFormula,'After Lookups')

 #EMBED(%SyncWindowAfterLookup,'Sync Record routine, after lookups')

!—————————————————————————

#EMBED(%ProcedureRoutines,'Procedure Routines')

#EMBED(%LocalProcedures,'Local Procedures'),HIDE

This starts with the required #GROUP statement which identifies the group for use in #INSERT statements.

The #IF(NOT %Window) error check detects whether the programmer has forgotten to create a window for the procedure. The #ERROR statement alerts the programmer to the mistake and #RETURN immediately aborts any further source generation for the procedure. The #DECLARE statements declare two template symbols for internal use by other #GROUPs that are called to generate source for the procedure, and a “flag” that determines whether a “progress” window is required by the procedure.

The next three #INSERT statements insert #GROUPs that contain #FIELD structures to define the standard prompts that appear on the Actions tab for BUTTON, ENTRY and CHECK controls placed on the procedure's window. These prompts allow the programmer to specify the standard actions these controls can take from this procedure.

The %GatherSymbols #EMBED statement has the HIDE attribute. This means that it will not appear in the list of available embed points for the programmer to insert code, making the embed point only available for internal use (for Code, Control, or Extension templates to generate code into).

The #INSERT(%FileControlInitialize) statement inserts a #GROUP that updates the symbols that keep track of the files used in the application w