Skip to main content
csgaraglino
Known Participant
December 3, 2010
Answered

StructCopy(form) will not hold?

  • December 3, 2010
  • 2 replies
  • 827 views

I am porting an application from CF5 to CF7 and in the app I have working code that copies the the contents of a form to a session variable so that I can use the information throughout the rest of the app.


<cfset session.stCustomerData = structCopy(form)>

This works great in CF5 and on the forms landing page the data is populated. But as soon as I leave the landing page (Link or Form Submit) the stCustomerData struct is missing from the session? ONLY the stCustomerData data?


If I loop through the form keys, it works.

<cfloop list="#StructKeyList(form)#" index="i">
<cfset SetVariable("session.stCustomerData.#i#", evaluate("form." & i))>
</cfloop>

I really don't want to scrube through 10 years woth of code to find all these! Any ideas?

    This topic has been closed for replies.
    Correct answer ilssac

    You might need to look at the difference between StructCopy() and Duplicate() as one only creates a pointer the the current data in memory and the other creates a true copy of the data in another memory location.  With the former, when the original data is destroyed (such as form data when the request is completed) all pointers at the data will also be gone.

    2 replies

    Community Expert
    December 3, 2010

    Use Duplicate instead of StructCopy.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

    Read this before you post:

    http://forums.adobe.com/thread/607238

    Dave Watts, Eidolon LLC
    ilssac
    ilssacCorrect answer
    Inspiring
    December 3, 2010

    You might need to look at the difference between StructCopy() and Duplicate() as one only creates a pointer the the current data in memory and the other creates a true copy of the data in another memory location.  With the former, when the original data is destroyed (such as form data when the request is completed) all pointers at the data will also be gone.

    csgaraglino
    Known Participant
    December 3, 2010

    Sweet, thaks, that did the trick....