Using Copy to create a new dynamic array in SmartMS

Top 

Example code : Using Copy to create a new dynamic array in SmartMS

// Defining an array

var

  a, b : array of Integer;

 

begin

// Instantiate an array

  a := new Integer[5];

  b := a.Copy();

  a[1] := 10;

  WriteLn( b[1] );  // 10

 

 

  a.SetLength(10);

  a[1] := 20;

  WriteLn( b[1] );  // 10

Result is: 10 and 10

------------------------------------------------------------------------

 

JS output:

      var a$54 = [];

      var b$18 = [];

      var i$5 = 0;

      a$54 = [0,0,0,0,0];

      $DIdxW(a$54,1,10,"");

      b$18 = a$54.slice(0);

      WriteLn($DIdxR(b$18,1,""));

      

       $ArraySetLen(a$54,10,0);

      $DIdxW(a$54,1,20,"");

      WriteLn($DIdxR(b$18,1,""));