[fpc-pascal] TThread.Queue vs TThread.Synchronize

Sven Barth pascaldragon at googlemail.com
Tue Feb 24 14:20:54 CET 2015


Am 24.02.2015 11:24 schrieb "Michael Schnell" <mschnell at lumino.de>:
>
> On 02/24/2015 11:12 AM, Sven Barth wrote:
>>
>>
>>
>> AFAIK Delphi doesn't use the term "closures" though conceptually
anonymous functions (as implemented by Delphi) are one way to achieve them.
>>
> What is the advantage of using a "closure" and/or an "anonymous function"
instead of just doing "free;" as the last instruction of a normal procedure
of some object ?
>

I'll comment in context to the example you gave for passing parameters to
Queue/Synchronize (a custom class with a suitable public method)

Closures:
- no need to declare a special class that handles the call
- no need to allocate a class
- no need to call "Free"

And with anonymous functions:
- the functionality is defined where it is needed (inside the parameter
clause of Queue/Synchronize or in case of nested procedures at least inside
the same method)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150224/4bc54d26/attachment.html>


More information about the fpc-pascal mailing list