In Delphi, function results should be assigned to the special Result variable.
While function results can be assigned to the function identifier, as in earlier versions of Pascal, this approach is no longer recommended as it can be confusing.
Assign the function result to the Result variable instead of the function identifier:
function GetFoo: TFoo; begin GetFoo := TFoo.Create; end;
function GetFoo: TFoo; begin Result := TFoo.Create; end;