Managed Event Question

G

Guest

Hi

I have a static event called PropertyChanged. PropertyChanged is a delegate
called PropertyChangedEventHandler(Object^ sender, PropertyChangedEventArgs^
e)

If I remove my PropertyChangeEventArg parameter from the delegate and
replace it with a string, the project compiles.

Here is a snippet of my code:

// FileSummary.h

public delegate void PropertyChangedEventHandler(Object^ sender,
PropertyChangedEventArgs^ e);

public ref class FileSummary sealed {
public:
static void SetProperty(String^ value);
static event PropertyChangedEventHandler^ PropertyChanged;
};

// FileSummary.cpp
void FileSummary::SetProperty(String^ value) {
...
PropertyChanged(FileSummary::typeid, gcnew PropertyChangedEventArgs(value));
}

// PropertyChangedEventArgs.h
public ref class PropertyChangedEventArgs sealed : EventArgs {
public:
PropertyChangedEventArgs(String^ value);
property String^ Value {
String^ get();
}

private:
String^ pValue;
};

// PropertyChangedEventArgs.cpp
PropertyChangedEventArgs::propertyChangedEventArgs(String^ value) {
pValue = value;
}

Sring^ PropertyChangedEventArgs::Value::get() {
return pValue;
}

I know I must be missing something, but like I mentioned, if I replace
PropertyChangedEventArgs^ in the delegate signature with String^ the project
compiles and works as expected.

Any help would be greatly appreciated.

Craig
 
A

Arnaud Debaene

Craig said:
Hi

I have a static event called PropertyChanged. PropertyChanged is a
delegate
called PropertyChangedEventHandler(Object^ sender,
PropertyChangedEventArgs^
e)

If I remove my PropertyChangeEventArg parameter from the delegate and
replace it with a string, the project compiles.
s said:
I know I must be missing something, but like I mentioned, if I replace
PropertyChangedEventArgs^ in the delegate signature with String^ the
project
compiles and works as expected.

Any help would be greatly appreciated.

Put PropertyChangedEventArgs declaration at the beginning of the header file
: Usual C++ symbol matching rules apply to C++/CLI, so the type
PropertyChangedEventArgs must have already been declared to the compiler
when it sees PropertyChangedEventHandler and FileSummary declarations (the
C++ compiler parses the file from top to bootom, only once)

Arnaud
MVP - VC
 
G

Guest

Hi Arnaud

I included PropertyChangedEventArg.h to the FileSummary.cpp, success!

Many thanks for you help, an easy one.

Craig
 

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