title: Returning a dynamic array from a function
body: <p>I'm working with Delphi 7.</p>
  
  <p>Here's my base class. The function <strong>load_for_edit()</strong> is supposed to return an array of strings which sounds like it does. The problem is not particularly here but further.</p>
  
  <pre><code>    ...
  
  type
      TStringArray = array of string;
  
      ...
  
      function load_for_edit(): TStringArray;
  
      ...
  
      numberOfFields: integer;
  
      ...
  
  function TBaseForm.load_for_edit(): TStringArray;
  var
      query: TADOQuery;
      i: integer;
  begin
      query := TADOQuery.Create(self);
      query.Connection := DataModule1.ADOConnection;
      query.SQL.Add('CALL get_' + self.table_name + '_id(' + self.id + ')');
      query.Open;
  
      numberOfFields := query.Fields.Count;
      SetLength(result, query.Fields.Count);
      for i := 0 to query.Fields.Count - 1 do
          result[i] := query.Fields[i].Value.AsString;
  end;
  </code></pre>
  
  <p>Next is the class that is a descendant of the base class and it's trying to receive an array from the base class's <strong>load_for_edit()</strong> function.</p>
  
  <pre><code>    ...
  
  type
      TStringArray = array of string;
  
      ...
  
  procedure TPublisherEditForm.FormShow(Sender: TObject);
  var
      rec: TStringArray;
  begin
      inherited;
      SetLength(rec, self.numberOfFields);
      rec := load_for_edit();                 // Compilation stops here
  end;
  </code></pre>
  
  <p>But, the application won't compile. Delphi spits out this error message:</p>
  
  <pre><code>Incompatible types
  </code></pre>
  
  <p>So, what this means is that the function <strong>load_for_edit()</strong> returns a data type that is different from the variable <strong>rec</strong>'s data type, though, as can be seen from their respective type declaration sections, their declarations are absolutely identical. I don't know what's going on here and what to do. Please, help me come up with a solution.</p>