Xbasic

COMPILE_TEMPLATE Function

Syntax

P COMPILE_TEMPLATE(C template[,C Macro1[,...C MacroN]])

Arguments

template

A string variable containing the code for one or more functions.

Macro1

Character

MacroN

Character

Description

Create a compiled Xbasic code object. The COMPILE_TEMPLATE() function allows you to define a series of functions that are stored in a string. You would use this function when you want to use a function in more than one script, but do not want to redefine it as part of each script. This technique is a very powerful alternative to creating global functions.

Example

Step 1: Define a string that contains one or more functions.

dim ptr as P
dim script as C
script = <<%code%
function foo as C (msg as C)
    ui_msg_box("Favorite Database", msg)
end function
%code%

Step 2: Compile the code the string and return an object pointer to the compiled code.

ptr = compile_template(script)

Step 3: This is how you call a function from the compiled code. Note that the function name is prefixed with the object pointer.

ptr.foo("Alpha Anywhere")

See Also