The Insert method with Arrays



The Insert method.
Smart pascal source code
procedure WriteLnArray(a: array of Integer); var i: Integer; begin Writeln(IntToStr(Length(a)) + ':{'); for i := 0 to High(a) do begin if i > 0 then Writeln(','); Writeln(IntToStr(a[i])); end; Writeln('}'); end; { unit1.pas } var a: array of Integer; begin a.Insert(0, 10); a.Insert(1, 20); WriteLnArray(a); // 2:{10,20} a.Insert(0, 0); WriteLnArray(a); // 3:{0,10,20} a.Insert(2, 15); WriteLnArray(a); // 4:{0,10,15,20} try a.Insert(-1, 0); except on E: Exception do Writeln(E.Message); end; try a.Insert(5, 0); except on E: Exception do Writeln(E.Message); end; WriteLnArray(a); // 6:{0,10,15,0,20,0}