473,398 Members | 2,188 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,398 software developers and data experts.

reference back to original value

I'm new to C#, and I have a question. For my program, I have 2 forms:
one to allow the user to pick a property and another to allow the user
to edit the property. They select the property they want to edit from
a TreeView.

Example:

string m_szCurrentPath;
object m_oCurrentTarget;

private void main_handleSelect( string szPath )
{

/* NUMBER OF SCREENS */
if ( szPath.CompareTo( "Basic Configuration\\Number of Screens" ) ==
0 )
{
btnEdit.Enabled = true;
/* BOX A REFERENCE TO THE VARIABLE WE WANT TO EDIT */
m_oCurrentTarget = m_szNumInputs;
m_iInputType = 0;
return;
}

/* IF WE GET HERE, THEN IT WASN'T AN EDITABLE PROPERTY */
btnEdit.Enabled = false;

} /* main_handleSelect */

private void btnEdit_Click(object sender, System.EventArgs e)
{
/* UNBOX THE VALUE TO A TEMP STRING */
string myvalue = (string)m_oCurrentTarget;
frmText mydlg = new frmText( ref myvalue, m_szCurrentPath );
DialogResult res = mydlg.ShowDialog();

if ( res == DialogResult.OK )
{
/*
* PROBLEM: THIS WON'T WORK
* OBJECT POINTS TO COPY ON THE HEAP
* I WANT TO UPDATE THE ORIGINAL VALUE.
*/
m_oCurrentTarget = myvalue;
}

}

There are 14 possible settings for the user to edit, and based off
their TreeView selection, I box a reference back to the string
variable holding that setting.

That's well and good, but when I go to update that original value, I
have a problem. The object boxing the value points to a copy on the
heap, not the original value. How do I reference and update the
original value. I'm trying to avoid using unsafe code and pointers.

Thanks!
T
Feb 22 '08 #1
0 908

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

Similar topics

11
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
6
by: Chris Simmons | last post by:
I know that a String is immutable, but I don't understand why this piece of code fails in nUnit: // BEGIN CODE using System; class Test { public static void Main( String args )
2
by: Anders Borum | last post by:
Hello! I was looking at marking objects with a changed state, once properties have been changed. The reason behind this is, that I would like to enlist such objects for processing in a...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
5
by: Tom | last post by:
If I have a container class that has a map member which stores pointers to objects that have been created via the new operator and I have a method that returns a entry in the map, would it be best...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
8
by: Frank Hauptlorenz | last post by:
Hello out there, I changed an existing and good working webservice from an wsHttpBinding to an NetTcpBinding. This is working (after trying some time) and has real a better performance! But...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.