473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing by ref?

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
}

Feb 20 '06 #1
3 978

<as*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
|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.
Feb 20 '06 #2
> 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 McPherran
www.McPherran.com
Feb 22 '06 #3
Greg wrote:
GetXMLRecord(NameValueCollection^% data)

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
Feb 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. ...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
8
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
6
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.