On 30/11/07 21:39, "Dave Addey" <listmail1 at addey dot com> wrote:
> Hi Daniel,
>
> That does help! A few more questions in that case:
>
> 1) Where should I store "d"? Can it be a property of the class myClass?
>
You can pretty much store it anywhere you want to. But it will always invoke
the method on the particular class instance that you created the delegate
INSTANCE from.
> 2) If I am registering a callback (using a declare), should I pass d as a
> ptr into the declare?
RB will convert a delegate instance into a Ptr type on the fly, so I think
you can either declare the callback as a ptr OR the delegate name. I seem to
recall just doing that myself recently.
>Or something else? I guess I'm not looking to invoke
> the delegate myself, but rather to have it called from a callback.
Actually - for callbacks I you cannot pass any delegate that was created
>from a class instance. Youre forced to use a global or shared method. The
Calling conventions are different.
>
> Thanks for the help,
>
> Dave.
>
>> From: Daniel Stenning <d0stenning at msn dot com>
>> Reply-To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
>> Date: Fri, 30 Nov 2007 21:34:41 +0000
>> To: "REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>"
>> <realbasic-nug at lists dot realsoftware dot com>
>> Conversation: Some questions about delegates
>> Subject: Re: Some questions about delegates
>>
>> 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!
>>>
>>> Dave.
>>> _______________________________________________
>>> Unsubscribe or switch delivery mode:
>>> <http://www.realsoftware.com/support/listmanager/>
>>>
>>> Search the archives:
>>> <http://support.realsoftware.com/listarchives/lists.html>
>>>
>>
>> Cheers,
>> Dan
>>
>>
>>
>>
>> _______________________________________________
>> Unsubscribe or switch delivery mode:
>> <http://www.realsoftware.com/support/listmanager/>
>>
>> Search the archives:
>> <http://support.realsoftware.com/listarchives/lists.html>
>
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
>
Cheers,
Dan
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|