0
votes

I'm trying to copy all the items from a generic array to a new one using TArray.Copy (Note: In Delphi XE7 the function has no documentation).

class procedure Copy<T>(const Source, Destination: array of T; SourceIndex, DestIndex, Count: NativeInt); overload; static;
class procedure Copy<T>(const Source, Destination: array of T; Count: NativeInt); overload; static;

The Source array turns into a zero filled array after executing the function:

var
  Source : TArray<Integer>;
  Destination : TArray<Integer>;
begin
  Source := [10, 20];
  SetLength(Destination, Length(Source));

  //here Source is [10, 20]

  TArray.Copy<Integer>(Source, Destination, 0, 0, Length(Source));

  //here Source is [0, 0]
end;

Why is it changing the Source array?

Can't reproduce in Delphi 10. - Ken Bourassa