Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passive Observers
Message
From
30/12/1998 12:38:42
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00171144
Message ID:
00171597
Views:
31
>Steve,
>
>>>>I am trying to implement an Observer object to send messages to objects on a form. The problem is that after I Subscribe my object to the Observer and then try to close the form on which the object exists, the form won't close. I assume this is because the Observer still has a reference to the object. I have tried releasing the object reference (from the Observer) in the objects Destroy method, but that didn't work. Where and how should the object "Unsubscribe"?
>
>You're right...you can't just put code in the Subscriber's Destroy() event, because it will never be executed when the form is closed when another object still holds a reference to the Subscriber.
>
>What you need is a mechanism that allows the form to tell its child objects (in particular any Subscribers) that it is about to be destroyed. Visual Basic has a mechanism called "Raising Events" (which we'll be getting in the next version of VFP!) that is used for this very thing. It allows your form to raise an event to which any interested objects can respond.
>
>That said, there is a way to emulate this functionality using VFP6's access/assign methods that I have implemented in the Mere Mortals Framework. Here's how:
>
>1. Create a property in your Subscriber objects such as "lDestroy".
>2. Create an assign method for the property
>3. In the assign method, enter code that has the object "Unsubscribe" itself
>4. In the Destroy method of your form, you can issue Thisform.SetAll('lDestroy', .T.)
>
>Whenever your form is destroyed, it issues the SetAll command which will trigger any Subscriber's lDestroy_Assign method, which in turn runs the code that unsubscribes the object.
>
>Regards,

Any way to implement that in VFP 5.0
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform