Posts tagged ‘Anonymous Methods’

Beware using anonymous methods in loops

Quick, what’s the output of this simple routine?
Continue reading ‘Beware using anonymous methods in loops’ »

How to leak a class you never defined

Quick, what’s wrong with this code?

[code lang="delphi"]
procedure ContrivedExample;
var
   factorial: TFunc;
begin
   factorial :=
      function(input: Integer): integer
      begin
         if (input = 0) or (input = 1) then
            result := input
         else result := input * (factorial(input - 1));
      end;

   writeln(factorial(5));
end;
[/code]

Continue reading ‘How to leak a class you never defined’ »

Under the hood of an anonymous method

I woke up this morning and checked DelphiFeeds, and found a very interesting post by Jolyon Smith about the use of the absolute keyword.  That reminded me that I had to go and write up this article.  Why?  Because it’s the only way I know of to get inside an anonymous method’s functor object and do some looking around.

Continue reading ‘Under the hood of an anonymous method’ »

What’s in a name-less method?

When I first saw the announcements for the new Delphi 2009 features, a little more than a year ago, my reactions went something like this:

Unicode: Hmm… looks interesting.
Generics: YES! FINALLY!
Anonymous methods: …huh?

I think that’s pretty much how everyone reacted to anonymous methods at first.  Continue reading ‘What’s in a name-less method?’ »