reference back to original value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TBass

    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_oCurrentTarge t;

    private void main_handleSele ct( string szPath )
    {

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

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



    } /* main_handleSele ct */



    private void btnEdit_Click(o bject sender, System.EventArg s e)
    {
    /* UNBOX THE VALUE TO A TEMP STRING */
    string myvalue = (string)m_oCurr entTarget;
    frmText mydlg = new frmText( ref myvalue, m_szCurrentPath );
    DialogResult res = mydlg.ShowDialo g();

    if ( res == DialogResult.OK )
    {
    /*
    * PROBLEM: THIS WON'T WORK
    * OBJECT POINTS TO COPY ON THE HEAP
    * I WANT TO UPDATE THE ORIGINAL VALUE.
    */
    m_oCurrentTarge t = 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
Working...