Name

Duplicate

Synopsis

                  
                  Duplicate(variable)

Creates a duplicate copy of variable without any references to the original. variable can be any ColdFusion datatype with the exception of component objects (COM, CORBA, and Java). Duplicate( ) overcomes problems associated with copying structures and queries. Generally, when copying a structure or query, any future change to the original object results in a change to the copy. Duplicate( ) eliminates this by making an independent copy of the original object. The duplicate copy isn’t affected by changes to the original. The Duplicate( ) function is especially useful for copying nested structures and XML objects, and should be used in place of the StructCopy( ) function. The following example illustrates the difference between copying and duplicating query objects:

<!--- create a query object ---> <cfset Products = QueryNew("ProductName, Color")> <cfset NewRows = QueryAddRow(Products, 1)> <cfset QuerySetCell(Products, "ProductName", "Widget", 1)> <cfset QuerySetCell(Products, "Color", "Silver", 1)> <!--- create a copy and a duplicate of the query ---> <cfset CopyProducts = Products> <cfset DuplicateProducts = Duplicate(Products)> <cfoutput> <b>Original:</b> You selected a #Products.Color# #Products.ProductName#.<br> <cfset QuerySetCell(Products, "Color", "Black", 1)> <b>Copy:</b> You selected a #CopyProducts.Color# #CopyProducts.ProductName#.<br> <b>Duplicate:</b> You selected a #DuplicateProducts.Color# #DuplicateProducts.ProductName#. ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.