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
myStringList := FuncStringList();
myStringList.Items.Count // <-- This causes an access violation
// function FuncStringList
function FuncStringList:TStringList;
var
vStrList:TStringList;
begin
vStrList := TStringList.Create;
...
// Fill the vStrList
Result := vStrList
vStrList.Free; //<- when i free here, this function will cause AccessViolation
end;
How can I return the TStringList and still free it in the local function?