Script preprocessor examples

This section describes two ways the script preprocessor can be used during application development.

Example 1

This example describes how the script preprocessor can be used to selectively compile code for the SQL and non-SQL versions of an application. A constant named SQL has been added to the dictionary using the Constant Definition window. If this constant is set to the value 0 and scripts are recompiled, the non-SQL code is used. If the constant is set to 1 and scripts are recompiled, the SQL code is used. In this example, a standard Pathname Setup form is opened when the non-SQL code is used. When the SQL code is used, a SQL version of the Pathname Setup form is opened.

#if SQL = 0
open form Pathname_Setup;
#else
open form SQL_Pathname_Setup;
#end if

Example 2

This example describes how the script preprocessor can be used to selectively include debugging code in a special “debug” build of an application. A constant named DEBUG has been added to the dictionary. If this constant is set to 0 and scripts are recompiled, the debug code isn’t compiled. If the DEBUG constant is set to 1 and scripts are recompiled, the debug code is compiled. In this example, the debug code displays any error that occurred as a result of the change statement.

{Set the value of the key field in the table buffer.}
'Seller ID' of table Seller_Data = 'Seller ID' of window 'Sellers';
{Release the lock on any record currently in the table buffer.}
release table Seller_Data;
{Attempt to retrieve the record from the table.}
change table 'Seller_Data' by Seller_Data_By_ID;

#if DEBUG
	{Display the number of any table error that occurred.}
	if err() <> OKAY then
		warning "Debug: Table error " + str(err()) + " on change operation in Seller ID script.";
	end if;
#end if

if err() = OKAY then
	{Record was successfully read. Copy the information to the
	 window.}
	copy from table 'Seller_Data';
	{Enable the Delete button and clear the window change flag.}
	clear changes form Sellers;
	enable '(L) Delete Button';
end if;

{Lock the Seller ID field.}
lock 'Seller ID';

Using the script preprocessor to include or exclude debugging code has two advantages. First, you have more control over what operations the debugging code performs. This is more flexible than the debug statement, which only displays messages in test mode. Second, when you choose not to include debug code, it’s not compiled. This means it doesn’t use additional space in the dictionary or increase a script’s execution time.


Documentation Feedback