Jump to content
Mike Torrettinni

Common callback functions, or not?

Recommended Posts

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.

  • Thanks 1

Share this post


Link to post
Guest
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
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

@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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×