[Pas2js] Passing Static Array parameter issue
warleyalex
warleyalex at yahoo.com.br
Sat Feb 17 23:07:46 CET 2018
When you pass dynamic arrays, Pas2JS treat dynamic arrays as a reference
type, you don't need to use var keyword to pass as reference. This is OK!
but when you pass static arrays, I think we have a minor issue, for
instance:
-----------------
type
TFixedSizeArray = array [0..9] of Integer;
TDynamicArray = array of Integer;
procedure SomeProc(fixed : TFixedSizeArray; dynamico : TDynamicArray);
begin
fixed[0] := fixed[0] + 1;
SetLength(dynamico, 20);
dynamico[0] := fixed[0] + dynamico[0];
end;
var f : TFixedSizeArray;
d : TDynamicArray;
begin
f[0] := 100;
SetLength(d, 10);
d[0] := 50;
SomeProc(f, d);
WriteLn(IntToStr( f[0]) ); // pas2js returns 101 ---> the expected
value would be 100
WriteLn(IntToStr( d[0]) ); //151 --> correct
-----------------------------------
pas2js emitt: ---------> $mod.SomeProc($mod.f,$mod.d);
I think the correct is: --> $mod.SomeProc($mod.f.slice(0),$mod.d);
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list