User Guide

Table Of Contents
Strings 53
You can also create a structure by assigning a value in the structure. For example, the following
line creates a new structure called MyStruct with a key named MyValue, equal to 2:
<cfset MyStruct.MyValue=2>
Note: In previous ColdFusion versions, this line created a Variables scope variable named
"MyStruct.MyValue" with the value 2.
After you create a structure, you can use functions or direct references to manipulate its contents,
including adding key-value pairs.
You can use either of the following methods to reference elements stored in a structure:
StructureName.KeyName
StructureName["KeyName"]
The following examples show these methods:
depts.John="Sales"
depts["John"]="Sales"
When you assign an existing structure to a new variable, ColdFusion does not create a new
structure. Instead, the new variable accesses the same data (location) in memory as the original
structure variable. In other words, both variables are references to the same object.
For example, the following line creates a new variable, myStructure2, that is a reference to the
same structure as the myStructure variable:
<cfset myStructure2=myStructure>
When you change the contents of myStructure2, you also change the contents of myStructure. To
copy the contents of a structure, use the ColdFusion
Duplicate function, which copies the
contents of structures and other complex data types.
Structure key names can be the names of complex data objects, including structures or arrays.
This lets you create arbitrarily complex structures.
For more information on using structures, see Chapter 5, “Using Arrays and Structures,” on
page 97.
Queries
A query object, sometimes referred to as a query, query result, or record set, is a complex
ColdFusion data type that represents data in a set of named columns, similar to the columns of a
database table. The following ColdFusion tags can create query objects:
cfquery
cfdirectory
cfhttp
cfldap
cfpop
cfprocresult
In these tags, the name attribute specifies the query object’s variable name. The QueryNew
function also creates query objects.