Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delegate & events

Status
Not open for further replies.

MarcoMB

Programmer
Oct 24, 2006
61
IT
Can someone help me to understand the differences between the event-delegate mechanism in class definition in Visual Basic and Visual C++?Or better...exist a event-delegate mechanism in Visual C++? defining a class in visual c don't require an events definition, but in Visual basic 6.0 the .cls creation module gives possibility to create method,properties but also events called by RaiseEvent...so what the difference from Visual C++ and Visual basic?
 
From what I know of delegates, I'd assume they're callbacks in C++.

This is what happens on a callback. When an event fires, control is passed to the callback which does what it is meant to do before returning control to the event loop. Is that what happens with delegates?

The events are mapped to callbacks. If you look for BEGIN_MAP and END_MAP in an MFC program, you will see the mapping of events to callbacks.
 
i think that callback functions are a type of functions that the operating system calls when needed, for example in response of some messages...in message_map we can see that message such as WM_COMMAND are related to his function... i don't know if it can be considered as a callback function...and i don't know if we can compare this system with that of visual basic,that has the ability to create objects class with events to relate to functions thanks to RaiseEvent instructions...the delegate system also is related with ActiveX object and the UserControl...it's quite confusing...
 
Any function can take a callback function parameter, not just system calls. Take a look at the qsort() function; it takes a pointer to a function that tells it how to compare the values...

Aren't Delegates & Predicates the same thing? I'm not a big fan of VB, so I only know the basics.
 
so you're saying that every functions called by another function that receive it as a parameter can be considered a callback function?
 
That's the way I've always thought of a callback function. Does VB do it differently?
 
i found some people talking about delegates related with ActiveX objects and UserControl, to share event from UserControl to ActiveX user , in other words we can share the userControl interface and interfaces of the other control types that make the ActiveX control so that the user could find those events in the final ActiveX, thanks to delegate mechanism...in VB6.0..what you say?what's the correspondig system in VC++?
 
It is a callback. The ancient term (if you want to go back 20/30 odd years) is a callback. Why MS has to invent delegates is beyond me. They could have called them callbacks but the term probably wasn't sexy enough. Since it is a new language that they have invented, they can call it whatever they want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top