title: Getting object as a result from func/proc in Delphi
body: <p>What is the <strong>best practice</strong> for returning simple objects from functions / procedures in delphi?</p>
  
  <p>eg. 2 kinds of code:</p>
  
  <p><strong>pass created object as reference</strong>, populate object in Proc, destroy it afterwards</p>
  
  <pre><code>procedure Proc(var Obj: TMyObject);
  begin
    // populate Obj
  end;
  
  O := TMyObject.Create;
  try
    Proc(O);
    // manipulate populated object
  finally
    O.Free;
  end;
  </code></pre>
  
  <p>or
  <strong>get created object as result from function</strong>, destroy after manipulation</p>
  
  <pre><code>function Func: TMyObj;
  begin
    Result := TMyObj.Create;
  end;
  
  O := Func;
  if O &lt;&gt; nil then
  begin
    try
      // manipulate
    finally
      O.Free;
    end;
  end;
  </code></pre>