Passing by ref?

  • Thread starter Thread starter asnowfall
  • Start date Start date
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
}
 
|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.
 
GetXMLRecord(NameValueCollection^% data)

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

:-)

Just a little humor about how out of hand the syntax is getting. :-)
 
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
 
Back
Top