View Issue Details

IDProjectCategoryView StatusLast Update
0033759FPCDocumentationpublic2019-02-15 16:38
ReporterSven BarthAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033759: Document SetLength() for multi dimensional dynamic arrays
DescriptionCurrent it is not explicitely documented that SetLength() for dynamic arrays can take multiple length arguments to create a "rectangular"* multi dimensional array. E.g. SetLength(arr, 10, 20), to create a dynamic array with 10 elements whereby each contains a dynamic array with 20 elements.

Of course it should also be documented that multi dimensional dynamic arrays don't need to be "rectangular"*. So something like this would be valid as well:

=== code begin ===

var
  a: array of array of array of LongInt;
  i, j, k: LongInt;
begin
  SetLength(a, 10, 5);
  SetLength(a[5], 3);

  for i := Low(a) to High(a) do
    for j := Low(a[i]) to High(a[i]) do begin
      SetLength(a[i, j], i * 10 + j);
      for k := Low(a[i, j]) to High(a[i, j]) do
        a[i, j, k] := i * 10000 + j * 100 + k;
    end;

  for i := Low(a) to High(a) do begin
    for j := Low(a[i]) to High(a[i]) do begin
      for k := Low(a[i, j]) to High(a[i, j]) do
        Writeln(a[i, j, k]);
      Writeln('-------');
    end;
    Writeln('=======');
  end;
end.

=== code end ===

* "rectangular" is written in quotes as arrays with more than three dimensions aren't rectangles of course. ;)
TagsNo tags attached.
Fixed in Revision1490
FPCOldBugId0
FPCTarget
Attached Files

Activities

Michael Van Canneyt

2018-06-28 11:04

administrator   ~0109102

Adapted setlength documentation for multi-dimensional case, added a couple of paragraphs to the dynamic arrays section of the reference manual, including your example. Many thanks!

Sven Barth

2019-02-15 16:38

manager   ~0114154

Thanks!

Issue History

Date Modified Username Field Change
2018-05-18 15:15 Sven Barth New Issue
2018-05-18 15:15 Sven Barth Status new => assigned
2018-05-18 15:15 Sven Barth Assigned To => Michael Van Canneyt
2018-06-28 11:04 Michael Van Canneyt Fixed in Revision => 1490
2018-06-28 11:04 Michael Van Canneyt Note Added: 0109102
2018-06-28 11:04 Michael Van Canneyt Status assigned => resolved
2018-06-28 11:04 Michael Van Canneyt Fixed in Version => 3.1.1
2018-06-28 11:04 Michael Van Canneyt Resolution open => fixed
2018-06-28 11:04 Michael Van Canneyt Target Version => 3.2.0
2019-02-15 16:38 Sven Barth Note Added: 0114154
2019-02-15 16:38 Sven Barth Status resolved => closed