title: How do i return an object from a function in Delphi without causing Access Violation?
body: <p>I have a delphi function that returns a TStringList, but when I return a value and try to use it I get a Access Violation Error i.e</p>
  
  <pre><code>myStringList := FuncStringList();
  myStringList.Items.Count   // &lt;-- This causes an access violation
  
  // function FuncStringList
  function FuncStringList:TStringList;
  var
    vStrList:TStringList;
  begin
  
    vStrList := TStringList.Create;
     ...
    // Fill the vStrList
  
    Result := vStrList 
    vStrList.Free;    //&lt;- when i free here, this function will cause AccessViolation
  end;
  </code></pre>
  
  <p>How can I return the TStringList and still free it in the local function?</p>