Anonymous methods let you supply methods to
other methods as parameters. Similar to method pointers but more
flexible, this is a feature takes some time to appreciate but is
used in other languages to build scaleable architectures such as
Google's MapReduce search algorithm.
type
TDemoAnonMethod = reference to function (n: Integer) :
integer;
procedure
DisplayModifiedValue(n : integer; AnonMethod:
TDemoAnonMethod);
begin
Display(AnonMethod(n));
end;
procedure
TForm1.Button1Click(Sender: TObject);
begin
DisplayModifiedValue(5, function (n : integer) :
integer
begin
Result := n * n;
end
);
// displays 25
DisplayModifiedValue(10, function (n : integer) :
integer
begin
Result
:= n + n;
end
); //
displays 20
end;