Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
JonathanBigelow #1
Assigning structures to arrays
Can somebody explain to me why this is happening? I don't get it.... I'm
trying to create an array of structures using the code below. Interestingly
enough, clearing the structure in line 8 of the code clears the structure that
was already assigned to position 1 of the array. I figured that, after
assigning it as another variable, that clearing the structure would only affect
the variables.field structure. I'm building a global data validation CFC and
want to be able to pass it an array of structure with the data needed to
validate each field. Can anybody help me out with another solution for this
without having to create field1, field2, field3, etc. structures???
<cfset arrFields = arrayNew(1)>
<cfset field = structNew()>
<cfset field.name = "fieldname">
<cfset field.type = "numeric">
<cfset field.minLen = "2">
<cfset field.maxLen = "10">
<cfset arrFields[1] = field>
<cfset structClear(field)>
<cfset field.name = "fieldname2">
<cfset field.type = "date">
<cfset arrFields[2]= field>
<cfdump var="#arrFields#">
JonathanBigelow Guest
-
Nesting Arrays within arrays.
How do i nest an array inside another array? something like array(i).aray2(j); Can I do that? -
Arrays/Structures in CFLOOP
From the code below you can see basically what I am trying to accomplish: to set up a CFLOOP from an earlier query, an insert some permutation of... -
Shopping cart with arrays and structures
Hello all- I'm only on line 3 of building a shopping cart, and it already has issues. I'm following online instructions on how to build a shopping... -
Assigning Numbers
I am relatively new to FM and am trying to figure out a solution to this problem; A database has x number of records all with the assigned number... -
assigning recordsource to tab
"Jim" <creveille@excite.com> wrote in message news:0a3d01c35527$a4d95d60$a601280a@phx.gbl... Using the Change event of the TabControl and... -
blewis #2
Re: Assigning structures to arrays
Instead of:
<cfset arrFields[1] = field>
Use:
<cfset arrFields[1] = StructCopy(field)>
When you assign the structure to that array location, you are just using
pointer to the structure. What you really want is a separate copy, so that you
are reuse it.
blewis Guest
-
Adam Cameron #3
Re: Assigning structures to arrays
> <cfset arrFields[1] = StructCopy(field)>
A caveat to this:>
> When you assign the structure to that array location, you are just using
> pointer to the structure. What you really want is a separate copy, so that you
> are reuse it.
structCopy() only deep copies the first "level" of structures, nested
structs are still copied by reference.
duplicate() deep copies the whole lot. Actually it does too good a job of
doing this and is actually in itself buggy, but generally speaking it's
what you want to use instead of structCopy().
In the specificed example, structCopy() would indeed work fine, though, as
the structs contain no other structs.
--
Adam
Adam Cameron Guest



Reply With Quote

