aArrayArray to be duplicated. It may contain one or more dimensions.
AdvPL GuideAClone( <aArray> )Duplicates an array, including nested arrays in multidimensional structures.
AClone() creates an independent copy of the supplied array. Unlike a simple assignment, which makes two variables point to the same structure, AClone() replicates the elements and nested arrays. Use it when the routine must change the copy without changing the original array.
AClone( <aArray> )aArrayArray to be duplicated. It may contain one or more dimensions.
Returns a new array with the same content as the supplied array, preserving nested arrays when they exist.
User Function AClone1()
Local aArray1 := { 10, 20, 30 }
Local aArray2 := AClone(aArray1)
Local nIndex := 0
For nIndex := 1 To Len(aArray2)
MsgInfo( CValToChar(aArray2[nIndex]) )
Next nIndex
ReturnThe cloned array contains the same values as the original array: 10, 20 and 30.
User Function AClone2()
Local aOriginal := { {"Product", 10}, {"Service", 20} }
Local aCopy := AClone(aOriginal)
aCopy[1][2] := 99
MsgInfo("Original: " + CValToChar(aOriginal[1][2]))
MsgInfo("Copy: " + CValToChar(aCopy[1][2]))
ReturnChanging the copy does not change the original array value, including nested arrays.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.