On Tue, 08 Sep 2009 09:22:30 -0400, Saaa <em...@needmail.com> wrote:


"Steven Schveighoffer" <schvei...@yahoo.com> wrote in message
news:op.uzxs4wyreav...@localhost.localdomain...
On Sun, 06 Sep 2009 18:54:47 -0400, Saaa <em...@needmail.com> wrote:

I'd like to set D's delegate to a method which is not yet available (like
c.method).
I solved this by encapsulating the method within a function literal, but
I
also need to know whether
the method is available or not when calling the delegate.
I could do this by making the function literal include the null-checking
code, but is there maybe a better solution to this problem?
The delegate is supposed to change a variable within the D class.
Hope you understand it :)

A delegate is a struct with a data pointer and a function pointer.  You
can access the individual parts via .ptr and .func (I believe).  You can
even change them via those properties.

does that help?

-Steve

I did read that part.
The problem lies more in that I'd like to point to something which is not
there yet.
In the code 'c.method()' is not there yet, as c is null.
Maybe I should create a dummy object for c to point to in stead of null ?
That way I point the delegate to the dummy method and ignore it as long as
it is pointing
to the dummy method :)
The only drawback to this is that all objects I want to point the delegate
to,
need to somehow be convertable to the dummy type (interface/abstract class),
meaning it will be less flexible.

Hm... I'm still confused. Why not just set the delegate to null? Why do you need to have the delegate set to something?

There are ways to do it, without having a class instance, but it is messy.

-Steve

Reply via email to