Posts

Showing posts from August, 2018

Mysterious Case Of Wrong Value

Anonymous methods in Delphi give us two things.

The first is the ability to write method code inline - passing it directly as a parameter to another method (function/procedure) or directly assigning it to a variable of the appropriate anonymous method type.

The second one is the ability to capture (use in method body) variables from the context in which a particular anonymous method is defined. This is especially useful for various callback and task related patterns because we can standardize (simplify) method signature and still have access to all necessary data from the outer context. Simply put, for every variable needed to perform particular functionality inside the method, we don't have to introduce another parameter.

Neat!

You decide to put together a simple piece of code to explore new possibilities.
uses System.SysUtils; procedure Test; var Functions: array of TFunc<Integer>; Func: TFunc<Integer>; i: Integer; begin SetLength(Functions, 5); for i :…