It's important to note that the delegate stores a strong ref to the
instance behind your back, which can wreak havoc if you rely on
things automatically cleaning up after themselves. In general I'd
think delegates that held weak refs and fired exceptions when
"Invoked" on a Nil object would be more useful, but I'm sure RS had
their reasons for the current implementation.
Frank.
<http://developer.chaoticbox.com/>
On 30-Nov-07, at 4:34 PM, Daniel Stenning wrote:
> Delegates contain a reference to the object instance that the
> method is on,
> IF you create a delegate from a method on a class instance as
> opposed to
> from a shared method or global method.
>
> First define the delegate - say called mydelegate in a module.
>
> then if you do
>
> Dim cinstance as New myClass
> Dim d as mydelegate = AddressOf cinstance.method1
>
> You will find that when d.Invoke(...) gets called that it will call
> method1
> on the instance you created ( cinstance )
>
> Hope this helps.
>
> On 30/11/07 21:17, "Dave Addey" <listmail1 at addey dot com> wrote:
>
>> I’m working on my RBScript-based controller code, and it’s all
>> going well –
>> but I have one more challenge....
>>
>> I’ve created a generic “Controller” class. The code for the
>> controller is
>> in an RBscript. I want to be able to register a callback, which
>> will call a
>> callback method on a controller class instance. I think this
>> might be where
>> I should use delegates?
>>
>> Historically, I’ve always had to use global module methods for
>> callbacks.
>> This has the downside that I don’t know (from within the callback)
>> which
>> controller object triggered the callback. Since my different
>> controller
>> types may need to use the same callback template (e.g. two UInt32
>> params,
>> returning a UInt32), I won’t even know which type of controller
>> caused the
>> callback, let alone which instance of the controller, in order to
>> pass the
>> callback event on to the controller for processing.
>>
>> I’m rather hoping that delegates give me a way to set up these
>> callbacks
>> using class-instance methods as the callback target. But I can’t
>> work out
>> what the code would be to do this. Do I need to define a delegate
>> in a
>> module? Do I need a property on the class to represent the
>> callback method?
>> Where would the callback code go?
>>
>> Any help much appreciated!
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|