How to test if a delegate or event is empty

R

RFOG

In C# is very easy:

if(myDelegate==null)
//Install it.

but in C++/CLI that does not work:

if(myDelegate==nullptr)
//Install it.

gives:

Error C3918:usage requires 'member' to be a data member

But myDelegate has operator == overloaded. I don't understand why it fails.
If I try some like this:

myDelegate->GetInvocationList()->Length==0

I get same error.

And other variations.
--
Visita mi blog: http://rfog.blogsome.com
Libros, ciencia ficción y programación
========================================
La amistad es más difícil y más rara que el amor. Por eso, hay que salvarla
como sea.
-- Alberto Moravia. (1907-1990) Escritor italiano.
 
B

Ben Voigt

RFOG said:
In C# is very easy:

if(myDelegate==null)
//Install it.

but in C++/CLI that does not work:

if(myDelegate==nullptr)
//Install it.

gives:

Error C3918:usage requires 'member' to be a data member

Use a custom event, like this:

private:

//! \brief MulticastDelegate chain of event handlers for the \ref Closed
event.

System::EventHandler^ CloseHandlers;

public:

virtual event System::EventHandler^ Closed

{

void add( System::EventHandler^ handler )

{

CloseHandlers += handler;

}

void remove( System::EventHandler^ handler )

{

CloseHandlers += handler;

}

}
 
Top