Wiki Home

BINDEVENT Question


Namespace: VB
I am using FoxPro 9 and my concern is that I am not using BindEvent() as it was intended to be used. I have bound an Event to a Delegate and want to use the return value of my Delegate but the return value of the event is stored in lcValue regardless of the order in which I call them (nFlag 0 or 1) . The example below gets the point across and lcValue is always .T.

From http://blogs.msdn.com/calvin_hsia/archive/2005/11/03/488939.aspx
"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".

BINDEVENT(This, "ReturnTrue", This, "ReturnFalse", 1) &&Event called before Delegate

Local lcValue
lcValue = .ReturnTrue()

*
*
PROCEDURE ReturnTrue

RETURN .T.
ENDPROC

*
*
PROCEDURE ReturnFalse

RETURN .F.
ENDPROC


Hi MysteryPoster,

Event Handlers are not supposed to return results... they are simply handling an event. Therefore, it isn't really proper to "call" an event handler. Instead, the event should be "raised", then all associated event handlers will be called. So things look more like this:
BINDEVENT(This.Control, "SomethingHappened", This, "Handle_SomethingHappened", 1)

*
* In the control's code that publishes "SomethingHappened"
PROCEDURE Control.SomethingHappened
  THIS.FlagThatSomethingHappened = .T.
ENDPROC
* In the control's code that publishes "SomethingHappened"
PROCEDURE Control.Click
  RAISEEVENT(THIS,'SomethingHappened')
ENDPROC


* In the form using the above control:
PROCEDURE Handle_SomeThingHappened
  * Uh oh: Something Happened! We gotta DoSomething!
  THISFORM.DoSomething
ENDPROC


Why is it you are trying to use BINDEVENT to change the result of a function? The more appropriate way would be sub-classing. - ?wgcs
...or use a Decorator Pattern -- Steven Black


Category Open Questions
( Topic last updated: 2005.11.06 03:17:31 AM )