[fpc-pascal] Copy dynamic array
Bart
bartjunk64 at gmail.com
Tue May 15 13:11:39 CEST 2018
On Tue, May 15, 2018 at 12:06 PM, Maciej Izak <hnb.code at gmail.com> wrote:
> you can just use :
>
> NewArray := Copy(OldArray);
Mind you, if OldArray is an array of array, Copy() will copy the
reference to the "second" array, not the actal data.
var
a,b: array of array of TSomeType;
SetLength(a, 5, 5);
a[0,0] := VarOfTSomeType;
b := copy(a);
a[0,0] := SecondVarOfTSomeType;
writeln(b[0,0]); //prints SecondVarOfTSomeType.
You would need to do b[i] := copy(a[i]) in a loop to copy the data.
Bart
More information about the fpc-pascal
mailing list