Anonymous procedures (Was: Re: [fpc-devel] for-in-index loop)

Alexander Klenin klenin at gmail.com
Sat Jan 26 16:46:13 CET 2013


On Sun, Jan 27, 2013 at 1:59 AM, kyan <alfasud.ti at gmail.com> wrote:
>> I assume this is because anonymous functions are not plain methods. Thus
>> they are not compatible with TMethod (the type behind "procedure/function of
>> object"). They are instead based on a different (internal) type.
>
> Please take a look at this:
> http://blog.barrkel.com/2010/01/using-anonymous-methods-in-method.html

While this article confirms my understainding of them Delphi implementation,
it does not offer a solution.
The solution must come at the language level -- for example, make
TMethod managed type
and fully unify "procedure", "procedure of object" and "reference to procedure".
This will of course incur some performance cost, but since event
variables are in 99% of cases
created and destroyed together with components, and components are
quite heavy anyway,
I suspect the cost will be negligible, especially with the help of
clever enough optimizer.
Further, after that, since all events will become object instances anyway,
C#-style event stacking may become feasible, replacing rather cumbersome
hand-made chaining or "AddHandler/RemoveHandler" interfaces.

--
Alexander S. Klenin



More information about the fpc-devel mailing list