Dexterity Pragma Pre-compiler directives

David Meego - Click for blog homepageMost Dexterity developers would have seen the pragma(disable warning LiteralStringUsed) command used at some stage to avoid literal string warnings when hard coded strings are needed as part of a script. This can often be the case when building SQL where clauses or pass through SQL, sanScript or macro code. 

However this is only one of the pragma pre-compiler directives available. The information below has been "borrowed" from the Dexterity help file. I wanted to highlight the other pragma commands which can be used to remove warnings when they are not needed.

One example I have found useful is when the parameters of a procedure or function are not all used in your trigger handling script.  Using the UnusedVariable pragma can remove the warnings generated.


Pragma reference
The following is a list of the pragmas available to control warnings generated by the sanScript compiler. Each warning can be disabled by the following code:

pragma(disable warning constant);

The warning is re-enabled by the following code:

pragma(enable warning constant);

LiteralStringUsed
The LiteralStringUsed pragma setting turns off the warning generated by using literal strings in scripts. The following example shows this setting.

 local string error_string;

{Turn off the warning for literal strings}
pragma(disable warning LiteralStringUsed);

error_string = "This is an invalid user name.";

{Turn the literal string warning back on}
pragma(enable warning LiteralStringUsed);

PossibleInfiniteLoop
The PossibleInfiniteLoop pragma setting turns off the warning generated when a possible infinite loop is detected.The following example shows this setting.

 pragma(disable warning PossibleInfiniteLoop);
while true do
    
    if 'Result' = true then
        exit while;
    end if;

end while;
pragma(enable warning PossibleInfiniteLoop);

TypeMismatch
The TypeMismatch pragma setting turns off the warning generated when a possible loss of data is detected when performing assignments. The following example shows this setting.

 local integer int_val;
local long long_val;

pragma(disable warning TypeMismatch);

int_val = long_val;

pragma(enable warning TypeMismatch);

UnusedVariable
The UnusedVariable pragma setting turns off the warning generated when an unused variable or parameter is detected.The following example shows this setting.

 local integer unused;

pragma(disable warning UnusedVariable);

Note: The UnusedVariable setting should not be enabled again before the end of the script. It will apply only to the current script. This option is handy when parameters for procedure and function trigger handling scripts are not used.  For trigger handling scripts, you have to match all the parameters even if you don't use them all.


For more information on handling Literal Strings and other pre-compiler directives and commands see the following articles:

Information about how to handle literal string warnings by using messages in Dexterity in Microsoft Dynamics GP (KB 943178) Secure Link

Pragma Option suppress or turn off Dexterity Compiler String Warning Messages (KB 850877) Secure Link

How to write Dexterity source which behaves differently for different versions

 

Hope this information is handy.

David

02-Feb-2011: Add note about the UnusedVariable setting and trigger handlers scripts for functions and procedures.