<p style="padding:0 0 0 0; margin:0 0 0 0;">Hi,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">is there a way how to have dynamic array "inside" another dynamic array?</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">program project1;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">{$mode objfpc}{$H+}</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">uses</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> {$IFDEF UNIX}</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> cthreads,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> {$ENDIF}</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> Classes, SysUtils</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> { you can add units after this };</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">{$R *.res}</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">type</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> TDynArray = array of Integer;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> PTDynArray = ^TDynArray;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">var aArray, aNewArray: TDynArray;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aNewStart: Integer;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> SetLength(aArray, 300);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> writeln('Length of aArray ', length(aArray));</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aNewStart:=100;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aArray[aNewStart+5]:=42;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aNewArray:=@aArray[aNewStart];</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aNewArray[5]:=42;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> writeln('Length of aNewArray ', length(aNewArray));</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">end. </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">So aNewArray begin at aArray[100] and have length=200 and I could write</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 13.3333px;">NewArray[5]:=42; i</span><span style="font-size: 13.3333px;">nstead of a</span><span style="font-size: 13.3333px;">Array[aNewStart+5]:=42;</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">After all, memory is allocated correctly.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 13.3333px;">Code above gives "Invalid pointer operation" w</span><span style="font-size: 13.3333px;">hile this code</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 13.3333px;"> aNewArray:=PTDynArray(@aArray[aNewStart])^;</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 13.3333px;"> aNewArray[5]:=42; </span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 13.3333px;">gives "Range check error".</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Thanks.</p>