1. PreProcessor & EXE-Compiler

<< Click to Display Table of Contents >>

Navigation:  2. Components > 1. PreProcessor & EXE-Compiler >

1. PreProcessor & EXE-Compiler

1.2 #ONCE / #OEND - Prevent multiple parsing of same code

Previous Top Next


Preprocessor-Directives

 

#ONCE / #OEND.

Include code-parts only once

 

 

Intention

 

All Commands starting with a "#" are Preprocessing Commands. These commands will influence the code before it is actually starting.These commands have no access to Variables and Runtime Resources, as they work in the Preprocessor, which is before Runtime.

The #ONCE and #OEND is a preprocessor command. The block between #ONCE and #OEND will not be read two times. There are two versions of the #ONCE command.

 

First version:

The #ONCE without any parameters. In this case the internal preprocessor uses the name of the actual loaded file as parameter. This will prevent the whole file from being loaded a second time. even if the block is somewhere inside the file.

 

Second version:

To just block a part of a code, use #ONCE [parameter-string]. In this case the parameter string will be stored in an internal memory and compared to any further call to #ONCE.

If this string is found a second time, the whole enclosed Block is been removed before any further processing is done.

This way, you can prevent files which are included with #INC: from being loaded and processed multiple times.

For example if the files contain MACRO Definitions. You do not want them to be loaded and parsed several times. Even if they are called from multiple incclude files.

 

There is no internal space after #ONCE, anything after the "#" is taken as part of the string. You can use the : or many other signs for formatting, these will however be part of the string. Variables are not resolved after #ONCE because this is done at Preprocessing-time, not at runtime.

 

 

 

Syntax:

 

#ONCE[P1]

 

P1 - string which identifies the block as unique.

 

 

Example:

 

'----------------------------------------

' Macro/#ONCE-Example 1

'----------------------------------------

' Minimum Number of parameters is set to zero

: %MyMacroA 0

#ONCE:ME

PRT.Number of Parameters:§§§00-Parameter=§§§01

#OEND

' Replace the MEX with ME to prevent the block from

' being processed.

#ONCE:MEX

PRT.Number of Parameters:§§§00-Parameter=§§§01

#OEND

END%

 

' Minimum Number of parameters is set to 1

: %MyMacroB 1

%MyMacroA Mytext

PRT.Number of Parameters:§§§00

END%

 

 

%MyMacroA Mytext

 

%MyMacroB Mytext

 

 

DMP.

END.

 

 

 

Parameter Explanation:

-

 

 

Remarks:

-

 

 

Limitations:

-

 

 

See also:

! Smarty's Preprocessor

1.1 #INC: - Pre-Processor File-Include

1.2 #ONCE / # OEND - Multiple Include Protection

1.8 : - MACRO-Definitions

1.4 #IF ... #EIF - Decisions in Macros