T
TBass
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
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