Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downcasting Objects

Status
Not open for further replies.

TazzMann

Programmer
Jul 25, 2001
79
US
Hello All!
I have two objects, one that is read only and one that is read-write. I am trying to morph from Readonly to Readwrite. Below is the code I am currently using to morph:

Code:
private void btnCreate_Click(object sender, System.EventArgs e) 
		{
			try
			{
				m_roAddress = null;
				m_roAddress = new RSMedical.System.rwAddress();
			}
			catch (System.Exception ex)
			{
				System.Console.WriteLine(ex.ToString());
			}
		}
However when stepping through the code, when it gets to the line
Code:
m_roAddress = new RSMedical.System.rwAddress();
I get an exception stating that it is an invalid cast. What am I doing wrong?

Thanks in advance for the help!

Tazzmann
 
What is the type of m_roAddress ?
I think if you declare somewhere:
Code:
object m_roAddress =null;
then the object assignment must work unless there are not other errors.
Having m_roAddress as object type, then you can cast it to other allowed/implemented casts.
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top