title: delphi - how to use declare and use pointer to the const array in a const record?
body: <p>I have a few const arrays of the same base type but different sizes, and I need to point to them in the const records. The code below compiles successfully, but finishes with error.</p>
  
  <pre><code>type
    Toffsets = array of integer;
  
    Trec = record
               point1: Tpoint;          //complete size
               point2: Tpoint;
               aOffsets:  ^Toffsets;
             end;
  
  const
    cOffsetsA: array [0..3] of integer = (7, 4, 2, 9);
    cOffsetsB: array [0..5] of integer = (1, 2, 3, 4, 5, 6);
  
    cRec1: Trec = (
      point1:   (x: 140; y: 46);
      point2:   (x: 5; y: 7);
      aOffsets: @cOffsetsA;
    );
  
    cRec2: Trec = (
      point1:   (x: 40; y: 6);
      point2:   (x: 5; y: 7);
      aOffsets: @cOffsetsB;
    );
  </code></pre>
  
  <p>In my code I need to access data from the cOffsetsA/B arrays having a pointer to the record. I tried to do it like this:</p>
  
  <pre><code>var pMyRec: ^Trec;
  ...
  pMyRec := @cRec1;
  ...
  i := pMyRec^.aOffsets^[0];
  </code></pre>
  
  <p>and this causes error - 'Access violation  ... read of address 000000...'</p>
  
  <p><strong>Can anybody explain is wrong here and how to fix it, how should it be done?</strong></p>
  
  <p>Probably I will also have to add the _length field in the record, which will hold the size of the array the pointer is pointing to; this is not a problem.</p>
  
  <p>Best regards,
  LUK</p>