The answer is no: [WayBack] Hi all, Can we truly assert that an array returned from a function is always a new true copy and that this is guaranteed to not change in between compil… – Ugochukwu Mmaduekwe – Google+
From Primož book and comment:
Depending on how you create this array.
For example, the following code outputs 42, not 17.
program Project142;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;function Bypass(const a: TArray<integer>): TArray<integer>;
begin
Result := a;
end;var
a, b: TArray<integer>;begin
SetLength(a, 1);
a[0] := 17;
b := Bypass(a);
a[0] := 42;
Writeln(b[0]);
Readln;
end.You can use `SetLength(arr, Length(arr))` to make array unique. Changing Bypass to the following code would make the test program emit 17.
function Bypass(const a: TArray<integer>): TArray<integer>;
begin
Result := a;
SetLength(Result, Length(Result));
end;
–jeroen






