Hi All.

I just discovered that SetLength(Var S: Array; NewLength: Integer) has an undocumented (appenrently unlimited number of) overloaded functions.

Any multi dimentional arrays may be sent to SetLength with appropriate dimension sizes. Making the following possible:

program SetArrayLength;

var
  Int2Array: Array of Array of Integer;
  Int3Array: Array of Array of Array of Integer;
// ...etc

begin
  SetLength(Int2Array, 5, 5);
  SetLength(Int3Array, 5, 5, 5);
// ... etc

  Int2Array[2][2]    := 2;
  Int3Array[2][2][2] := 3;
  WriteLn(IntArray[2][2]);
  WriteLn(IntArray[2][2][2]);
end;


Is this a feature, bug or undocumented behaviour?

Afair, this was allowed back in Delphi7 (which is where i copied some of my old code from), but i'm not sure whether it was documented.

At least the current RTL documentation on SetLength does not include other variants than the one with just a single length specifier.
https://www.freepascal.org/docs-html/rtl/system/setlength.html

Best regards,
Torsten.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to