Ken Ismert
KIsmert at TexasSystems.com
Thu Jan 15 17:39:40 CST 2004
>One thing you say intrigues me though. You mention Implements allowing a >custom callback scheme and sending messages. How does this work? How does >the callback communicate between class instances? John, Interesting, the difference in perspectives: after your experience with true object languages, you find VBA limiting, while I cut my teeth on non-object languages, and find Implements a revelation. I'd love to work in a true OOP language that supports inheritance, but feel it would take some time to fully grasp its power and use it effectively. The callback scheme can be summarized as follows: 1. The callbacks are defined as methods in the ICallback interface: ' Insert this code in Class module ICallback Public Sub Message(sBody As Text) End Sub 2. Class CWannaMessage, wanting to receive messages, implements ICallback: Implements ICallback Private Sub ICallback_Message(sBody As Text) Debug.Print sBody End Sub 3. The CWannaMessage object makes a CCaller object, and passes a reference to itself: Set rCaller = New CCaller rCaller.Setup Me 4. CCaller's setup code looks like this: Private mrCallback as ICallback Public Sub Setup(CallbackObj As ICallback) Set mrCallback = CallbackObj End Sub 5. When CCaller wants to send a message: mrCallback.Message "Hello, you!" 6. Since you now have circular object references, CCaller must also provide a way to release its callback reference: Public Sub Shutdown Set mrCallback = Nothing End Sub 7. CWannaMessage must shutdown its caller when it isn't needed, or neither object will terminate: rCaller.Shutdown This example shows a one-on-one conversation, but it could easily be extended for multiple callers. CWannaMessage could maintain a collection of CCallers, and pass each CCaller its name or index on Setup, which CCaller could then pass back when it sends its Message. Or CCaller could just pass a reference to itself (Me) back to CWannaMessage. In any case, ICallback would have to be suitably extended. I calculate the obtuseness of this post at 135 degrees, a 5 degree improvement over the last. -Ken ps: I have some relatively simple form management code using interfaces. It allows a Parent form to open a Child, and be notified when it closes. I'll send you it if you're interested.