MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 275

Table of Contents

Advertisement

Defining and Using Custom Functions
You can use functions that manipulate many rows of a query outside such tags.
There you can pass in a query and loop over it in the function. The following
example, which changes text in a query column to uppercase, illustrates using a
function to modify multiple query rows.
function UCaseColumn(myquery, colName)
{
}
Evaluating strings in functions
If your custom function evaluates parameters that contain strings, you must make
sure that all variable names in the string are fully qualified to avoid conflicts with
function local variables. In the following example, you get the expected results if you
pass the fully qualified argument, Variables.myname, but you get the unexpected
function local variable value if you pass the argument unqualified, as myname.
<CFScript>
<!--- whoops, collides with local variable name --->
#readname("variables.myname")#
<!--- ok. Finds the name passed in
Passing arrays to custom functions
Arrays, unlike structures, are passed to custom functions by value. This means the
function gets a new copy of the array and the array in the calling page is unchanged
by the function. For more efficiency, and if you want a function to modify an array in
the calling page, store an array as a member of a structure, pass the structure, and
reference the array through the structure.
The following example passes an array and a structure containing the array to a
function. The function changes the array contents using both of the parameters. The
code calls the function and displays the resulting array contents. The change the
var currentRow = 1;
for (; currentRow lte myquery.RecordCount;
currentRow = currentRow + 1)
{
myquery[colName][currentRow] =
UCase(myquery[colName][currentRow]);
}
myname = "globalName";
function readname( name )
{
var myname = "localName";
return (Evaluate( name ));
}
</CFScript>
<cfoutput>
The result of calling readname with "myname" is:
#readname("myname")# <br>
The result of calling readname with "variables.myname" is:
</cfoutput>
--->
255

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion 5

Table of Contents