On Sat, Jan 2, 2010 at 5:44 AM, Paul Ishenin <webpi...@mail.ru> wrote:
> Jonas Maebe wrote:
>>
>> http://edn.embarcadero.com/article/33336
>>
>> Note that even Delphi doesn't have them yet ("it might also turn up in
>> Delphi in the future").
>>
>
> Looks as something related to:
> http://en.wikipedia.org/wiki/Anonymous_function#Delphi ? If so then this is
> already implemented in delphi.

Something I've really found useful in C#/.NET is lamda functions and
capturing locals (closures). This feature really solves asynchronous
design for me at least. If you can follow this code (note below how
url and dimension locals are captured):

// inside a static class called Async ...
public delegate object Task();
public delegate void Complete(object result);
public static void Execute(Task task, Complete complete) { ... }

Which can then lead to code like this:

downloading = true;
progressControl.Status = ProgressStatus.Busy;
Async.Execute(() => Download.BitmapScaled(url, maxWidth, maxHeight),
DownloadComplete);

... and in DownloadComplete:

private void DownloadComplete(object result)
{
  downloading = false;
  progressControl.Status = ProgressStatus.None;
  if (result is Exception)
    progressControl.Text = "An error occurred during download";
  else
  {
    progressControl.Text = String.Empty;
    imageControl.Image = result as Bitmap;
  }
}
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to