FPiette 383 Posted October 26, 2020 2 hours ago, Mike Torrettinni said: Well, not sure how to answer this, because my understanding is event=callback. Your are right: an event is a kind of callback. But not all callbacks are events. In Delphi there is a pattern for the events. I explained that pattern in a few previous messages and @Fr0sT.Brutal expressed it again using different words. 1 Share this post Link to post
Lars Fosdal 1792 Posted October 26, 2020 I like anon procs too - but unfortunate variable captures can be easy to miss. Share this post Link to post
Guest Posted October 26, 2020 53 minutes ago, Lars Fosdal said: I like anon procs too - but unfortunate variable captures can be easy to miss. Thereis a lot to say about the compiler warnings. But in this respect, IMHE, they work in this context. You do not agree? Share this post Link to post
David Heffernan 2345 Posted October 27, 2020 18 hours ago, Mike Torrettinni said: I very rarely use anonymous functions, so I assume the limitation (compared to callback) is that it can only be used within already executed code. You can't just assign it to something, because it's anonymous (not defined anywhere). Right? No. That makes no sense. Anonymous methods are just procedural types with variable capture. Share this post Link to post
Lars Fosdal 1792 Posted October 27, 2020 @Dany Marmur Unless they added new warnings in 10.4, they do not? It is perfectly legal to capture a variable or property whose content may change during execution, while you wanted to capture a specific value of that variable or property. It is easy to miss. The workaround is to always assign that variable to a local variable that you reference in the anon method. Share this post Link to post
Mike Torrettinni 198 Posted October 27, 2020 42 minutes ago, David Heffernan said: No. That makes no sense. Anonymous methods are just procedural types with variable capture. Correct, well I probably didn't phrase my statement correctly, as I'm not too experienced with anonymous methods. And as @Rollo62 has shown, a few posts prior, there's a lot you can do with anonymous methods. Share this post Link to post
Guest Posted October 27, 2020 3 hours ago, Lars Fosdal said: It is perfectly legal to capture a variable or property whose content may change during execution, while you wanted to capture a specific value of that variable or property. Ah, yes - *that* pitfall can bite. No, no warning for that that i know of. Share this post Link to post