` Detecting template instances (Robert Fred, Meyer) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Templates: Detecting template instances
1998-09-11 -- Robert Fred, Meyer
 
Newsgroups: topspeed.products.c4 Editors note: Please note that some lines may wrap in the template code. ===================================================================== When you have a PROCEDURE EXTENSION template that may be included in more than one procedure and you want only one occurrence of CODE or DATA generated regardless of the number of procedures that template is included in, the following template code seems to ensure that only one occurrence of the DATA or CODE is generated. -------------------------------------------------------------------- #EXTENSION(My_Extension,'My Extension'),PROCEDURE #! #AT(%CustomGlobalDeclarations) #!===> Include only once per template #DECLARE(%ThisProcedure) #DECLARE(%ThisTemplate) #DECLARE(%ThisInstance) #DECLARE(%ThisExit) #SET(%ThisProcedure,%Procedure) #SET(%ThisTemplate,%ActiveTemplate) #SET(%ThisInstance,%ActiveTemplateInstance) #ENDAT #! #AT(%GlobalData) #! or #AT(%GlobalMap), #AT(%ProgramSetup), etc. #SET(%ThisExit,1) #FOR(%PROCEDURE),WHERE(%ThisExit = 1) #FOR(%ActiveTemplate),WHERE(%ThisTemplate = %ActiveTemplate) #IF(%ThisInstance = %ActiveTemplateInstance) #! ! The DATA or CODE here will only generate once regardless ! of the number of procedures that include this template. #! #ENDIF #SET(%ThisExit,0) #ENDFOR #ENDFOR #FIX(%Procedure,%ThisProcedure) #FIX(%ActiveTemplate,%ThisTemplate) #FIX(%ActiveTemplateInstance,%ThisInstance) #EDNAT --------------------------------------------------------------------- With the exception of #AT(%CustomGlobalDeclarations) to the #ENDAT, all of the above code must be included #AT every place you want only one occurrence of DATA or CODE and that DATA or CODE must be placed where indicated above. ===================================================================== If you want a first occurrence and last occurrence for purposes of building such things as CASE or IF structures use the following: --------------------------------------------------------------------- #EXTENSION(My_Extension,'My Extension'),PROCEDURE #! #AT(%CustomGlobalDeclarations) #!===> Include only once per template #DECLARE(%ThisProcedure) #DECLARE(%ThisTemplate) #DECLARE(%ThisInstance) #DECLARE(%ThisExit) #SET(%ThisProcedure,%Procedure) #SET(%ThisTemplate,%ActiveTemplate) #SET(%ThisInstance,%ActiveTemplateInstance) #ENDAT #! #AT(%GlobalData) #! or #AT(%GlobalMap), #AT(%ProgramSetup), etc. #SET(%ThisExit,1) #FOR(%PROCEDURE),WHERE(%ThisExit = 1) #FOR(%ActiveTemplate),WHERE(%ThisTemplate = %ActiveTemplate) #IF(%ThisInstance = %ActiveTemplateInstance) #! ! The DATA or CODE here will only generate for the first occurrence. #! #ENDIF #SET(%ThisExit,0) #ENDFOR #ENDFOR #FIX(%Procedure,%ThisProcedure) #FIX(%ActiveTemplate,%ThisTemplate) #FIX(%ActiveTemplateInstance,%ThisInstance) #! ! The DATA or CODE here will generate for all occurrences. ! This includes the frist and last occurrence. #! #SET(%ThisExit,1) #FOR(%PROCEDURE),WHERE(%ThisExit = 1),REVERSE #FOR(%ActiveTemplate),WHERE(%ThisTemplate = %ActiveTemplate),REVERSE #IF(%ThisInstance = %ActiveTemplateInstance) #! ! The DATA or CODE here will only generate for the last occurrence. #! #ENDIF #SET(%ThisExit,0) #ENDFOR #ENDFOR #FIX(%Procedure,%ThisProcedure) #FIX(%ActiveTemplate,%ThisTemplate) #FIX(%ActiveTemplateInstance,%ThisInstance) #ENDAT --------------------------------------------------------------------- With the exception of #AT(%CustomGlobalDeclarations) to the #ENDAT, all of the above code must be included #AT every place you want a first and last occurrence.


Today is April 26, 2024, 9:02 pm
This article has been viewed 35107 times.
Google search has resulted in 14 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: