Pb firing events with VC 2005

C

Chris

Hi,
Still having problems with converting my VC 2003
project to VC 2005 beta, this time with events (using the new
C++ syntax).

My class defines the following event:
event PropertyChangedEventHandler ^ PropertyChanged;

(it uses the System.ComponentModel.PropertyChangedEventHandler delegate)

When I try to fire the event:
PropertyChanged(this, gcnew PropertyChangedEventArgs("Size"));

I get a 'System.NullReferenceException'

If I look in the "Autos" Debug window, I see:

- this
<PropertyChanged> <undefined value>


Is it normal ?
What am I doing wrong ?

Chris.
 
T

Tomas Restrepo \(MVP\)

Chris,
Still having problems with converting my VC 2003
project to VC 2005 beta, this time with events (using the new
C++ syntax).

My class defines the following event:
event PropertyChangedEventHandler ^ PropertyChanged;

(it uses the System.ComponentModel.PropertyChangedEventHandler delegate)

When I try to fire the event:
PropertyChanged(this, gcnew PropertyChangedEventArgs("Size"));

I get a 'System.NullReferenceException'

If I look in the "Autos" Debug window, I see:

- this
<PropertyChanged> <undefined value>


Is it normal ?
What am I doing wrong ?

Do you have any delegates attached to this event? Usually, when coding calls
to an event, you always need to check if it is null first (in which case no
one has subscribed to the event yet)
In the end, the event is only a multicast delegate with another extra piece
of metadata...
 
C

Chris

Tomas said:
Do you have any delegates attached to this event? Usually, when coding calls
to an event, you always need to check if it is null first (in which case no
one has subscribed to the event yet)
In the end, the event is only a multicast delegate with another extra piece
of metadata...

OK. I hadn't realized that the value of the delegate
should be tested. I had no receiver connected to the event.
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top