title: Delphi generic classes and dynamic arrays
body: <p>I have read multiple times the answers in <a href="https://stackoverflow.com/questions/14383093/what-are-the-reasons-to-use-tarrayt-instead-of-array-of-t">this</a> question about the <code>TArray&lt;T&gt;</code> and the <code>array of T</code>. From what I have understood the use of the first is more versatile than the latter because for a dynamic array I should declare a type like...</p>
  
  <pre><code>type
     TMyFlexibleArray = array of Integer;
  </code></pre>
  
  <p>... that is needed (in certain cases) because I cannot return an <code>array of Integer</code> for example. Instead, of course, I can return a generic type. Dynamic arrays don't have a fixed length and memory for them is reallocated with the SetLength procedure. TArray is a generic class with static methods; the documentation about it states:</p>
  
  <blockquote>
    <p>You should not create instances of this class, because its only
    purpose is to provide sort and search static methods.</p>
  </blockquote>
  
  <hr>
  
  <p>They have two different natures/functions but do they have the same result (for example when passed as parameter or when I just need a flexible container)? I see that TArray has also some useful method.</p>
  
  <p>Is is correct if I say that <code>TArray&lt;T&gt;</code> is a dynamic array built with generics and <code>type K = array of T</code> is an own dynamic array (a custom one)? In my question I assume that they are equivalent in their function of being dynamic arrays (and I prefer the generic way just for comfort).</p>