The BINDEVENT( ) Function allows you to attach code to run when other code is executed. It’s sort of like an event hook.
The first example below has a method called “Foobar” which is called to return a value. After BindEvent is called, the method is called again. The “FoobarHandler” code is executed. Now there are 2 routines that were called when the original “Foobar” method was called, each of which return a value. Which Return value should be used?
Event handlers handle events. They don’t have return values (except maybe to say whether the event was indeed handled).
The released version of VFP8 used the return value of the delegate. It gets even more complicated when there are multiple routines bound to the original, some executing before and some executing after. Customers reported such issues so that was changed for the released version of VFP9: the Return value of the original method is used. That way, the behavior is consistent and predictable. Also, adding a BindEvent to code won’t change the original author’s intended return value.
oevent = CREATEOBJECT("cEvent")
ohandler = CREATEOBJECT("cHandler")
DEFINE CLASS cEvent AS custom
RETURN PROGRAM()+" Main Return Value"
DEFINE CLASS cHandler AS custom
?"Here I am in "+PROGRAM()
RETURN PROGRAM()+" Handler Return Value"
This code binds 2 methods to the original Foobar:
RETURN PROGRAM()+" Handler2 Return Value"