bg5
05-13-2012, 12:42 PM
I have trouble with copying TPA...
program new;
var
tpa1 ,tpa2 : TPointArray;
a ,b :integer;
begin
tpa1 := [Point(1,1),Point(2,2) ];
tpa2 := tpa1;
OffsetTPA(tpa2,Point(2,2));
writeln(tpa1);
writeln(tpa2);
a := 2;
b := a;
b := 3;
writeln(a);
writeln(b);
end.
[(3, 3), (4, 4)]
[(3, 3), (4, 4)]
2
3
As you see tpa2 := tpa1; doesn't copy tpa1 to tpa2 ,but copy tpa1's pointer...differently then with simple types. There is already function CopyTPA ,but it's leaking and don't have wrapper , so I won't use it ,because I want to do this operation very frequently. Only possible way I see is iteration ,but it will slow down my script.
Iteration I mean:
hi := high(tpa1);
SetLength(tpa2,hi+1);
for a:=0 to hi do
tpa2[a] := tpa1[a];
any ideas?
program new;
var
tpa1 ,tpa2 : TPointArray;
a ,b :integer;
begin
tpa1 := [Point(1,1),Point(2,2) ];
tpa2 := tpa1;
OffsetTPA(tpa2,Point(2,2));
writeln(tpa1);
writeln(tpa2);
a := 2;
b := a;
b := 3;
writeln(a);
writeln(b);
end.
[(3, 3), (4, 4)]
[(3, 3), (4, 4)]
2
3
As you see tpa2 := tpa1; doesn't copy tpa1 to tpa2 ,but copy tpa1's pointer...differently then with simple types. There is already function CopyTPA ,but it's leaking and don't have wrapper , so I won't use it ,because I want to do this operation very frequently. Only possible way I see is iteration ,but it will slow down my script.
Iteration I mean:
hi := high(tpa1);
SetLength(tpa2,hi+1);
for a:=0 to hi do
tpa2[a] := tpa1[a];
any ideas?