Delphi 2009, among some cool stuff, has also just got Anonymous methods. I've seen the examples, and the blog posts regarding anonymous methods, but I don't get them yet. Can someone explain why I should be excited?
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- iOS objective-c object: When to use release and wh
- DBGrid - How to set an individual background color
相关文章
- Best way to implement MVVM bindings (View <-> V
- Windows EventLog: How fast are operations with it?
- How to force Delphi compiler to display all hints
- Coloring cell background on firemonkey stringgrid
- Will java allow to use functional interfaces as me
- HelpInsight documentation in Delphi 2007
- Can RTTI interrogate types from project code at de
- How to scope closure's variables in CF10?
Please have a look at closures.
Delphi anonymous functions are closures.
These are created within other functions and as such has access to the scope of that function. This is even so if the anonumous function is assigned to a function parameter that is called after the original function is called. (I will create an example in a moment).
The above method assigns two anonymous functions to the fields F1 and F2. The first increases the local variable and the second showe the value of the variable.
You can now call both functions, and they access the same a. So calling F1 twice and F2 once shows a 3. Of course this is a simple example. But it can be expanded to more usefull code.
In the multi threading environment, anonymous functions can be used in a call to Synchronise, which eliminates the need for countless methods.