delegate !is null
Steven Schveighoffer
schveiguy at yahoo.com
Thu Sep 10 03:59:04 PDT 2009
On Tue, 08 Sep 2009 18:13:56 -0400, Saaa <empty at needmail.com> wrote:
> Hope this one makes any sense :)
>
> C c = new C;
> C mouseOverObject = c;
>
> int delegate() deleg = &mouseOverObject.getSomeVariable;
> mouseOverObject = null;
>
> int value;
> void write()
> {
> if(deleg !is null) //how do I make this check for (mouseOverObject !is
> null)?
if(mouseOverObject !is null)
That's the only way. A delegate does not magically become set to null
when you set the original object to null or delete the original object.
It is a separate pointer that is only set when you set it.
What you are asking is the equivalent of this:
int x = 5;
int y = x;
x = 0;
if(y != 0) // how do I check through y that x is now 0?
However, setting mouseOverObject to null does *not* destroy the object, as
long as the delegate exists, it is still pointing to the object, so it
will not be cleaned by the GC.
So your delegate is still valid as long as you don't delete
mouseOverObject manually.
-Steve
More information about the Digitalmars-d-learn
mailing list