[fpc-pascal] Delphi compatible anonymous functions

Florian Klämpfl florian at freepascal.org
Fri May 16 18:18:58 CEST 2014


Am 16.05.2014 17:45, schrieb Craig Peterson:
> 
> 1) I want to use the OmniThreadLibrary.  Setting up objects and thread
> descendents is fine in moderation, but it's too much of a hassle when
> you just want a quick parallel for loop.

Isn't using anonymous methods in this case only a work around for missing OpenMP support?

> 
> To solve that, years ago we started using cooperative threads
> (coroutines/fibers) in our GUI thread.  I re-implemented ShowModal so it
> handles the details internally.  When you call it it displays the
> dialog, just like the ShowModalNonBlocking() call would, but then
> switches to another "thread" that processes messages.  When the dialog
> is finally closed the running thread switches back to the ShowModal
> call, which then exits like normal.  As a result, even though we can
> have several independent modal dialogs up at once, the code is all
> identical to the first example.  Everything is nicely encapsulated and
> sharing state before and after the dialog is trivial.
> 
> Unfortunately, fibers introduce incompatibilities on both Windows and OS
> X, and are deprecated on OS X, so we need to stop using them.  They are
> by far the cleanest approach, and I'd keep using them if I had any
> choice whatsoever.
> 
> The second best alternative is to use closures and anonymous methods.

I still don't get how closures/anonymous methods help you to get rid of fibers? I mean, anonymous
methods are only a short cut; closures allow you to capture the state of the variables of the outer
scope even if the outer scope is left. But that's it?




More information about the fpc-pascal mailing list