[fpc-devel] Delphi anonymous methods

Aleksa Todorovic alexione at gmail.com
Mon Mar 4 11:29:03 CET 2013


On Mon, Mar 4, 2013 at 11:01 AM, Graeme Geldenhuys
<graeme at geldenhuys.co.uk>wrote:

> On 2013-03-04 01:47, Boian Mitov wrote:
> > vast improvements of the code and the readability.
>
> They are unreadable to me.
>
> > I recently started
> > rewriting our libraries with anonymous methods and that alone allowed for
> > cutting over 20000 lines of code
>
> Just my dropping method names? I doubt that.
>

It's not removing method names that cut all those lines, but whole class
declarations. Imagine situation where you want to call specific method as
callback but you also want to pass some parameters to that method. Your
options would be:

- declare callback interface as class, and call specific method in that
class (Java-style); you will need to set some fields of callback object
with specific parameters
- declare callback interface as method pointer, and call it (similar to
previous solution); again, you will need to set some fields of callback
objects
- declare callback interface as class or method pointer, and in advance add
parameter with type 'array of const' for user-defined parameters; would
work, but you would loose type-safety
- declare callback interface as function pointer, and pass
closure/anonymous method to it; let the compiler do all the magic, wrap-up
local variables for you and "send" appropriate values to specific function
call

There are definitely benefits from this feature, but they require different
architecture/design of your application.

Regards,
Aleksa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130304/d4c2ddde/attachment.html>


More information about the fpc-devel mailing list