
Creating and using structures
119
Copying structures
ColdFusion provides several ways to copy structures and create structure references. The
following table lists these methods and describes their uses:
The following example shows the different effects of copying, duplicating, and assigning structure
variables:
Create a new structure<br>
<cfset myNewStructure=StructNew()>
<cfset myNewStructure.key1="1">
<cfset myNewStructure.key2="2">
<cfset myArray=ArrayNew(1)>
<cfset myArray[1]="3">
<cfset myArray[2]="4">
<cfset myNewStructure.key3=myArray>
<cfset myNewStructure2=StructNew()>
<cfset myNewStructure2.Struct2key1="5">
<cfset myNewStructure2.Struct2key2="6">
<cfset myNewStructure.key4=myNewStructure2>
<cfdump var=#myNewStructure#><br>
<br>
A StructCopy copied structure<br>
<cfset CopiedStruct=StructCopy(myNewStructure)>
<cfdump var=#CopiedStruct#><br>
<br>
A Duplicated structure<br>
<cfset dupStruct=Duplicate(myNewStructure)>
<cfdump var=#dupStruct#><br>
<br>
A new reference to a structure<br>
<cfset structRef=myNewStructure>
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 new 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 replaces this function for most, if not all, purposes.
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 a variable’s scope without deleting the variable from the
original scope.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...