[fpc-devel] Parameters must match exactly?

Marcos Douglas md at delfire.net
Tue May 18 17:11:01 CEST 2010


Florian Klaempfl <florian at freepascal.org> wrote:
>
> Nobody doubts this, this is also why I wrote "normally" in my initial
> post. Nevertheless I didn't see a single valid reason yet why
> implementing the factory method pattern cannot be done using a function:
> - it is one of the basic programming principles: if a result is returned
> by a subroutine, use a function
> - it makes things more intuitive to read because it looks like a constructor
>

Florian Klaempfl <florian at freepascal.org> wrote:
>
> With a function result one can easily use the as-operator. I thought
> such simple things are clear without additional notes.

Now, I have a question:
If a function return an object, like Result := TStringList.Create, and
I use like that:

var
  sl: TStringList;
begin
  sl := myfunc;
  try
    // some code
  finally
     sl.Free;
  end;
end;

that is OK... but if a call without a variable for return, what will
happen with the object created inside the function? A memory leak?


Thanks,
Marcos Douglas



More information about the fpc-devel mailing list