Name

Duplicate — New as of ColdFusion 4.51

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 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 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.