sub main()
x=["one","two","three"]
something(x)
?"x=";x
stop
end sub
function something(y)
y[0]="four"
?"y=";y
sleep(10000)
end function
x = []
i = 0
for each el in y
x[i] = el
i = i+1
end for
"renojim" wrote:
I don't know if there's another way, but when I need to do something like this I create a new object and then iterate over all the members of the object I want to copy. For example:
x = []
i = 0
for each el in y
x[i] = el
i = i+1
end for
I'd be interested to know if there's an easier/better way.
-JT
[kbenson@brinstar source]$ cat rdDeepCopy.brs
function rdDeepCopy(v as object) as object
v = box(v)
vType = type(v)
if vType = "roArray"
n = CreateObject(vType, v.count(), true)
for each sv in v
n.push(rdDeepCopy(sv))
end for
elseif vType = "roList"
n = CreateObject(vType)
for each sv in v
n.push(rdDeepCopy(sv))
end for
elseif vType = "roAssociativeArray"
n = CreateObject(vType)
for each k in v
n[k] = rdDeepCopy(v[k])
end for
elseif vType = "roByteArray"
n = CreateObject(vType)
n.fromHexString( v.toHexString() )
elseif vType = "roXMLElement"
n = CreateObject(vType)
n.parse( v.genXML(true) )
elseif vType = "roInt" or vType = "roFloat" or vType = "roString" or vType = "roBoolean" or vType = "roFunction" or vType = "roInvalid"
n = v
else
print "skipping deep copy of component type "+vType
n = invalid
'n = v
end if
return n
end function
"TheEndless" wrote:
All objects are passed by reference, so even with this, the values in the array are references, unless they are base types (string, integer, boolean, etc), so to get a true copy, you'd need to recreate the object and copy all the way down the chain to the base types.