aOrigemSource array from which elements are copied.
AdvPL GuideACopy( <aOrigem>, <aDestino>, [nInicio], [nCont], [nPosDestino] )Copies elements from one array to another compatible destination array.
ACopy() copies elements from a source array into a destination array. It can define the starting source position, the number of copied elements and the starting destination position. Unlike AClone(), it assumes the destination array already has a compatible structure; it does not automatically resize the destination to make the copy possible.
ACopy( <aOrigem>, <aDestino>, [nInicio], [nCont], [nPosDestino] )aOrigemSource array from which elements are copied.
aDestinoDestination array that receives the copied elements. It must have a compatible structure.
nInicioInitial source-array position from which elements are copied.
Default:1nContNumber of elements copied. When omitted, the source array is considered through its last element.
nPosDestinoInitial destination-array position where elements are written.
Default:1Returns aDestino, a reference to the destination array that received the copied elements.
#Define CRLF Chr(13)+Chr(10)
User Function ACopy1()
Local aExample := {1, 2, {11, 22, 33}}
Local aBackup := {Nil, Nil, {Nil, Nil, Nil}}
Local cMessage := ""
ACopy(aExample, aBackup)
cMessage += "Copy[1] = " + CValToChar(aBackup[1]) + CRLF
cMessage += "Copy[2] = " + CValToChar(aBackup[2]) + CRLF
cMessage += "Copy[3][1] = " + CValToChar(aBackup[3][1]) + CRLF
cMessage += "Copy[3][2] = " + CValToChar(aBackup[3][2]) + CRLF
cMessage += "Copy[3][3] = " + CValToChar(aBackup[3][3])
MsgInfo(cMessage, "ACopy example")
ReturnThe elements from aExample are copied to aBackup, which was already created with a compatible structure.
User Function ACopy2()
Local aSource := {"A", "B", "C", "D"}
Local aTarget := {"", "", "", ""}
ACopy(aSource, aTarget, 2, 2, 3)
MsgInfo("Target: " + aTarget[1] + "," + ;
aTarget[2] + "," + aTarget[3] + "," + aTarget[4])
ReturnCopies two elements starting at source position 2 and writes them starting at destination position 3.
© 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.