Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Array copy problem

Keywords: 	 Array copy problem 

Question:

Please take a look at the following example
;********************************
total=3
array=ArrDimension(total)

ArrInitialize(array,0)

For counter=1 to total-1
array[counter]=counter
Next

; Note the values in the array

copy=array

; In the Winbatch Studio watchscreen:
; note that 2 arrays exist, both have the same values
; Now update only the 'copy' array

For counter=0 to total-1
copy[counter]="test"
Next

; Note the values in both arrays
; Values in 'array' also get updated

Exit
;********************************
 
So, when I update a value in the 'copy' array, the original array also gets updated. Is copying an array permitted and if so, is this a bug? Currently running Winbatch 2002K on a Windows 2000 machine.

Answer:

The variable"array" is a pointer to the data.
copy=array
Makes a duplicate of the pointer to the data. So now you have two variables pointing to the same chunk of data, not two seperate chunks of data.

See the udfArrCopy code in the following tech article: W15104