Passing by ref?

A

asnowfall

I am calling a function with a reference parameter. Inside the function
(GetXMLRecord)
I am changing the input parameter. When the function returns, input
parameter is not reflecting the change. This would have worked in C++,
but not here

What I am doing wrong? Pls help.


ref class ImageFileData
{
public NameValueCollection^ m_pNameValueCollection;
public:
ImageFileData()
{
m_pNameValueCollection = gcnew NameValueCollection;
}
int GetXMLRecord( NameValueCollection^ data)
{
if(m_pNameValueCollection->Count)
{
data = m_pNameValueCollection; ///VALUE set here to "data" does
not get

///here will not carried to caller
}
return 0;
}
}


public ref class Test : public System::Windows::Forms::Form
{
ImageFileData^ m_pImageFileData;
}
void Test :: initControlsFromXML( )
{
NameValueCollection^ objCustomData ;
m_pImageFileData->GetXMLRecord( objCustomData); //////VALUE set
inside function does
//not hold good when the function returns
}
 
W

Willy Denoyette [MVP]

|I am calling a function with a reference parameter. Inside the function
| (GetXMLRecord)
| I am changing the input parameter. When the function returns, input
| parameter is not reflecting the change. This would have worked in C++,
| but not here
|
| What I am doing wrong? Pls help.
|
|
| ref class ImageFileData
| {
| public NameValueCollection^ m_pNameValueCollection;
| public:
| ImageFileData()
| {
| m_pNameValueCollection = gcnew NameValueCollection;
| }
| int GetXMLRecord( NameValueCollection^ data)
| {
| if(m_pNameValueCollection->Count)
| {
| data = m_pNameValueCollection; ///VALUE set here to "data" does
| not get
|
| ///here will not carried to caller
| }
| return 0;
| }
| }
|
|
| public ref class Test : public System::Windows::Forms::Form
| {
| ImageFileData^ m_pImageFileData;
| }
| void Test :: initControlsFromXML( )
| {
| NameValueCollection^ objCustomData ;
| m_pImageFileData->GetXMLRecord( objCustomData); //////VALUE set
| inside function does
| //not hold good when the function returns
| }
|

GetXMLRecord(NameValueCollection^% data)
or
GetXMLRecord([Runtime::InteropServices::Out]NameValueCollection^% data)


Willy.
 
G

Guest

GetXMLRecord(NameValueCollection^% data)

or you can simply use:
GetXMLRecord(NameValueCollection^%#&@* data)

:)

Just a little humor about how out of hand the syntax is getting. :)
 
T

Tamas Demjen

Greg said:
or you can simply use:
GetXMLRecord(NameValueCollection^%#&@* data)

:)

Just a little humor about how out of hand the syntax is getting. :)

Why do you say that? In native C++ it was *&. Now it's ^%. You have to
be able to differenciate between native pointers and managed handles.
Not like in the old MC++ hell, when you had absolutely no idea what the
* was meaning.

Would it be better to write

GetXMLRecord(NameValueCollection __gc* __gc& data)

???

Tom
 

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