Alas, even StructCopy() is not enough. Use Duplicate() instead (CF4.5 only).
StructCopy() only does a shallow copy. Try the following code (3 files) and see what
happens to critters.mammals.dogs:
------------------------------------------------------------------------------------------
- StructTest1.cfm
------------------------------------------------------------------------------------------
<html>
<head>
<title>Copying Structs with StructCopy()</title>
</head>
<body>
<cfscript>
critters = StructNew();
critters.description = "This struct holds all the critters.";
critters.mammals = StructNew();
critters.insects = StructNew();
critters.marsupials = StructNew();
critters.mammals.description = "This struct holds all the mammals.";
critters.mammals.cow = "I say mooo.";
critters.mammals.cat = "I say meow.";
critters.mammals.dogs = StructNew();
critters.mammals.dogs.description = "This struct holds all the dogs.";
critters.mammals.dogs.greyhound = "I'm fast.";
critters.mammals.dogs.droopy = "I'm slow.";
critters.insects.description = "This struct holds all the insects.";
critters.insects.spider = "I eat other bugs by catching them in my web.";
critters.insects.cockroach = "I gross people out.";
critters.insects.ant = "I'm cool.";
critters.marsupials.description = "This struct holds all the marsupials.";
critters.marsupials.kangaroo = "I can jump really freakin far.";
critters.marsupials.koala = "I like eucalyptus.";
</cfscript>
<cfset crittersCopy = StructCopy(critters)>
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td colspan="2" align="center"><b>Copying Structs with
<code>StructCopy()</code></b></td>
</tr>
<tr>
<td align="center"><b>Critters</b></td>
<td align="center"><b>Critters Copy</b></td>
</tr>
<tr valign="top">
<td><cfmodule template="printStructTree.cfm" theStruct="#critters#"
theStructName="Critters"></td>
<td><cfmodule template="printStructTree.cfm"
theStruct="#crittersCopy#" theStructName="Critters Copy"></td>
</tr>
<tr>
<td colspan="2" align="center">
<b>Modify critters.mammals.dogs...</code></b>
<cfset critters.mammals.dogs = "dogs is gone!">
</td>
</tr>
<tr valign="top">
<td><cfmodule template="printStructTree.cfm" theStruct="#critters#"
theStructName="Critters"></td>
<td><cfmodule template="printStructTree.cfm"
theStruct="#crittersCopy#" theStructName="Critters Copy"></td>
</tr>
</table>
</body>
</html>
------------------------------------------------------------------------------------------
- StructTest2.cfm
------------------------------------------------------------------------------------------
<html>
<head>
<title>Copying Structs with Duplicate()</title>
</head>
<body>
<cfscript>
critters = StructNew();
critters.description = "This struct holds all the critters.";
critters.mammals = StructNew();
critters.insects = StructNew();
critters.marsupials = StructNew();
critters.mammals.description = "This struct holds all the mammals.";
critters.mammals.cow = "I say mooo.";
critters.mammals.cat = "I say meow.";
critters.mammals.dogs = StructNew();
critters.mammals.dogs.description = "This struct holds all the dogs.";
critters.mammals.dogs.greyhound = "I'm fast.";
critters.mammals.dogs.droopy = "I'm slow.";
critters.insects.description = "This struct holds all the insects.";
critters.insects.spider = "I eat other bugs by catching them in my web.";
critters.insects.cockroach = "I gross people out.";
critters.insects.ant = "I'm cool.";
critters.marsupials.description = "This struct holds all the marsupials.";
critters.marsupials.kangaroo = "I can jump really freakin far.";
critters.marsupials.koala = "I like eucalyptus.";
</cfscript>
<cfset crittersCopy = Duplicate(critters)>
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td colspan="2" align="center"><b>Copying Structs with
<code>Duplicate()</code></b></td>
</tr>
<tr>
<td align="center"><b>Critters</b></td>
<td align="center"><b>Critters Copy</b></td>
</tr>
<tr valign="top">
<td><cfmodule template="printStructTree.cfm" theStruct="#critters#"
theStructName="Critters"></td>
<td><cfmodule template="printStructTree.cfm"
theStruct="#crittersCopy#" theStructName="Critters Copy"></td>
</tr>
<tr>
<td colspan="2" align="center">
<b>Modify critters.mammals.dogs...</code></b>
<cfset critters.mammals.dogs = "dogs is gone!">
</td>
</tr>
<tr valign="top">
<td><cfmodule template="printStructTree.cfm" theStruct="#critters#"
theStructName="Critters"></td>
<td><cfmodule template="printStructTree.cfm"
theStruct="#crittersCopy#" theStructName="Critters Copy"></td>
</tr>
</table>
</body>
</html>
------------------------------------------------------------------------------------------
- printStructTree.cfm
------------------------------------------------------------------------------------------
<cfparam name="attributes.theStruct" default="">
<cfparam name="attributes.theStructName" default="No Struct Given">
<cfoutput>#attributes.theStructName#</cfoutput>
<cfif (IsStruct(attributes.theStruct))>
<ul>
<cfloop collection="#attributes.theStruct#" item="key">
<li>
<cfif IsStruct(attributes.theStruct[key])>
<cfmodule template="printStructTree.cfm"
theStruct="#attributes.theStruct[key]#" theStructName="#key#">
<cfelse>
<cfoutput>#key# =
#attributes.theStruct[key]#</cfoutput>
</cfif>
</li>
</cfloop>
</ul>
</cfif>
------------------------------------------------------------------------------------------
At 5:43 PM +0200 8/7/00, BOROVOY Noam wrote:
>Old Chinese saying: "If all else fails read the @#$% manual"
>
>' ... Use the StructCopy function when you want to create a physical copy of
>a structure. You can also use assignment to create a copy by reference. '
>
>If you want thread safe variables, and you want to copy a complex variable
>query / structure. A simple assignment is NOT enough! You must use
>StructCopy.
>
>HTH,
>Noam
>
> ----------
> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, 07 August 2000 17:08
> To: [EMAIL PROTECTED]
> Subject: Locking & Request Scoped Variables (was RE: Global
>Variables)
>
> Picking up on something Fred Sanders said in his reply:
>
> "...The request scope is a global thread safe variable scope.
> To get out of having to do locks I often make request. scoped
>pointers to
> whatever application scoped variables I've set. "
>
> I seem to remember Dave Watts mentioning on the CF-Talk list that
>pointers
> to shared memory variable scopes (ie. session, application, etc...)
>are no
> better from a locking perspective than the direct call to them. Did
>I
> misunderstand? Anyone care to clarify this request. pointer issue?
>
> Thanks,
>
> Chris
>
>
>
>----------------------------------------------------------------------------
>--
> To Unsubscribe visit
>http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/fusebox or
>send a message to [EMAIL PROTECTED] with 'unsubscribe' in
>the body.
>------------------------------------------------------------------------------
>To Unsubscribe visit
>http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/fusebox or send a
>message to [EMAIL PROTECTED] with 'unsubscribe' in the body.
------------------------------------------------------------------------------
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebarRsts&bodyRsts/fusebox or send a message
to [EMAIL PROTECTED] with 'unsubscribe' in the body.