By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,275 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,275 IT Pros & Developers. It's quick & easy.

InvokeMember for STRUCTURE and CLASS.

P: n/a
Hello,

why does the following code work for a CLASS, but not for a STRUCTURE?
(The first MsgBox returns '0,0', but I expected it to be '100,0'.)
(The second MsgBox returns 'Hello', as expected.)
REM Code in a button click event:

Dim objObject, objValue As Object

objObject = Activator.CreateInstance(GetType(System.Drawing.Po int))
objValue = 100
objObject.GetType.InvokeMember("X", System.Reflection.BindingFlags.Static Or
System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.Public Or
System.Reflection.BindingFlags.NonPublic Or
System.Reflection.BindingFlags.SetProperty, Nothing, objObject, New Object()
{objValue})
MessageBox.Show(objObject.X.ToString & "," & objObject.Y.ToString)

objObject = Activator.CreateInstance(GetType(System.Windows.Fo rms.TextBox))
objValue = "Hello"
objObject.GetType.InvokeMember("Text", System.Reflection.BindingFlags.Static
Or System.Reflection.BindingFlags.Instance Or
System.Reflection.BindingFlags.Public Or
System.Reflection.BindingFlags.NonPublic Or
System.Reflection.BindingFlags.SetProperty, Nothing, objObject, New Object()
{objValue})
MessageBox.Show(objObject.Text.ToString)
Thanks.
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.