4D v17.4

collection.copy( )

Home

 
4D v17.4
collection.copy( )

collection.copy( )  


 

The collection.copy( ) method returns a deep copy of the collection instance. Deep copy means that objects or collections within the original collection are duplicated and do not share any reference with the returned collection.

Notes:

  • This method does not modify the original collection.
  • If applied to a shared collection, copy( ) returns a regular (not shared) collection.

If the original collection contains pointer type values, by default the copy also contains the pointers. However, you can resolve pointers when copying by passing the ck resolve pointers constant in the resolvePtrs parameter. In this case, each pointer present in the collection is evaluated when copying and its dereferenced value is used.

Example  

 C_COLLECTION($col)
 C_POINTER($p)
 $p:=->$what
 
 $col:=New collection
 $col.push(New object("alpha";"Hello";"num";1))
 $col.push(New object("beta";"You";"what";$p))
 
 $col2:=$col.copy()
 $col2[1].beta:="World!"
 ALERT($col[0].alpha+" "+$col2[1].beta) //displays "Hello World!"
 
 $what:="You!"
 $col3:=$col2.copy(ck resolve pointers)
 ALERT($col3[0].alpha+" "+$col3[1].what) //displays "Hello You!"



See also 

New collection
OB Copy

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v17)
4D Language Reference ( 4D v17.1)
4D Language Reference ( 4D v17.2)
4D Language Reference ( 4D v17.3)
4D Language Reference ( 4D v17.4)