Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 104

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
<cfloop query="GetEmployees">
<cfif StructKeyExists(myStruct, LastName)>
<cfoutput>#LastName#: #mystruct[LastName]#</cfoutput><br>
</cfif>
</cfloop>
If the name of the key is known in advance, you can also use the ColdFusion
IsDefined("structure_name.key")>
However, if the key is dynamic, or contains special characters, use the
Note: Using
StructKeyExists
ColdFusion scopes are available as structures and you can improve efficiency by using
existence of variables.
Getting a list of keys in a structure
To get a list of the keys in a CFML structure, you use the
<cfset temp=StructKeyList(structure_name, [delimiter])>
You can specify any character as the delimiter; the default is a comma.
Use the
function to returns an array of keys in a structure, as follows:
StructKeyArray
<cfset temp=StructKeyArray(structure_name)>
Note: The
and
StructKeyList
or
functions to sort the results.
ListSort
ArraySort
Copying structures
ColdFusion provides several ways to copy structures and create structure references. The following table lists these
methods and describes their uses:
Technique
Use
Duplicate function
Makes a complete copy of the structure. All data is copied from the original structure to the new structure,
including the contents of structures, queries, and other objects. As a result changes to one copy of the structure
have no effect on the other structure.
This function is useful when you want to move a structure completely into a new scope. In particular, if a structure
is created in a scope that requires locking (for example, Application), you can duplicate it into a scope that does
not require locking (for example, Request), and then delete it in the scope that requires locking.
StructCopy function
Makes a shallow copy of a structure. It creates a structure and copies all simple variable and array values at the top
level of the original structure to the new structure. However, it does not make copies of any structures, queries, or
other objects that the original structure contains, or of any data inside these objects. Instead, it creates a reference
in the new structure to the objects in the original structure. As a result, any change to these objects in one
structure also changes the corresponding objects in the copied structure.
The
Duplicate
Variable assignment
Creates an additional reference, or alias, to the structure. Any change to the data using one variable name changes
the structure that you access using the other variable name.
This technique is useful when you want to add a local variable to another scope or otherwise change the scope of
a variable without deleting the variable from the original scope.
The following example shows the different effects of copying, duplicating, and assigning structure variables:
to test for the existence of a structure entry is more efficient than using
StructKeyList
functions do not return keys in any particular order. Use the
StructKeyArray
function replaces this function for most, if not all, purposes.
Last updated 1/20/2012
function, as follows:
IsDefined
function.
StructKeyExists
StructKeyExists
function, as follows:
99
.
IsDefined
to test for the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents