Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Create a Box, Arrow with properties from DataBase (Read 3995 times)
krebsd
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 9th, 2005
Create a Box, Arrow with properties from DataBase
Feb 21st, 2006 at 1:38pm
Print Post  
I have the following Table:

Class   Property   Value
____________________________
"Box"   "Style"      "1"
"Box"   "FillColor"  "FF00FF"
"Arrow""Headsize""5"
.....
...

Now I want to set all these values in a loop.
I found the System.Reflection-Class and tried the following things:

[code]Dim b As  Box = fc.CreateBox(10, 10, 90, 40)
       '1.Problem: b.getType() only returns MindFusion.WebChart.ItemType and this class doesn't support .GetProperty
       Dim t As Type = b.getType.GetType()
       Dim p As System.Reflection.PropertyInfo
       p = t.GetProperty("Style")

       p.SetValue(b, 3, Nothing)[/code]


This code now throws a null-reference-exception.
But it must work like this.

Thanks for your help in advance.

regards, Daniel.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #1 - Feb 21st, 2006 at 2:49pm
Print Post  
Hi,

Try using

b.GetType()

instead of

b.getType().GetType().

The latter returns the type of the ActiveItem enumeration, which does not have a Style property. The former returns the type of the Box class.

Stoyan
  
Back to top
 
IP Logged
 
krebsd
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 9th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #2 - Feb 22nd, 2006 at 6:29am
Print Post  
Stoyan,

b.getType() doesn't return System.Type.
It returns MindFusion.WebChart.ItemType.

And this cannot be casted into System.Type.

Dim t as System.Type = b.GetType()
occurs an compiler-error.

regards, Daniel.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #3 - Feb 22nd, 2006 at 9:02am
Print Post  
It seems VB.NET is case insensitive and hides the "Object.GetType' method when there is a "getType" defined in a class. Try the following

       Dim obj As Object
       obj = b
       Dim t As System.Type = obj.GetType()

Regards,
Stoyan
  
Back to top
 
IP Logged
 
krebsd
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 9th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #4 - Feb 22nd, 2006 at 11:15am
Print Post  
Stoyan,

i have now:

Code
Select All
Dim b As Box = fc.CreateBox(10, 10, 90, 40)


dim obj as object


obj=b
	  Dim t As Type = obj.GetType()
	  Dim p As System.Reflection.PropertyInfo
	  p = t.GetProperty("Style")

	  p.SetValue(obj, 3, Nothing) 



I've no more compile-errors, but a runtime error at the .SetValue method:

ArgumentException: Der Objekttyp kann nicht zum Zieltyp konvertiert werden.]
   System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) +0
   System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess) +317
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +23
   System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +159
   PromolPM.Element_GV.Element_GVPage.create_flow() +101
   PromolPM.Element_GV.Element_GVPage.OnLoad(EventArgs e) +699
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #5 - Feb 22nd, 2006 at 12:27pm
Print Post  
Hi,

Probably type conversion does not work when setting a value using reflection. Try passing some value from the BoxStyle enumeration instead of "3".

Stoyan
  
Back to top
 
IP Logged
 
krebsd
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 9th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #6 - Feb 22nd, 2006 at 2:41pm
Print Post  
Stoyan,

8) that works'

thanks a lot.

regards, Daniel.
  
Back to top
 
IP Logged
 
krebsd
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 13
Joined: Dec 9th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #7 - Mar 23rd, 2006 at 2:56pm
Print Post  
Stoyan, the next problem:

It's all now dynamicly but the value:

[code] Dim mi As MethodInfo = fc.GetType.GetMethod("CreateBox")
       Dim args() As Object = {10, 10, 90, 40}
       obj = mi.Invoke(fc, args)

       Dim t As Type = obj.GetType()
       Dim p As System.Reflection.PropertyInfo
       p = t.GetProperty("Style")
       Const mystyle As MindFusion.WebChart.BoxStyle = 3
       p.SetValue(obj, mystyle, Nothing)[/code]

If I try to set the mystyle dynamicly, I get a Null-Reference-Exception.

My code for that try:

[code]Dim str_class As String = "MindFusion.WebChart.BoxStyle"
       Dim str_value As String = "2"
       Dim theType As Type = Type.GetType(str_class)
       Dim o As Object = (CType(str_value, IConvertible)).ToType(theType, System.Globalization.CultureInfo.InvariantCulture)
       Dim b As Box = fc.CreateBox(10, 10, 100, 50)
       b.Style = o[/code]


But If I try that with a standard .net class e.g. "System.Int32" it works without any problems.
Here an example where I create an Int32 with the value 47:

[code]Dim str_class As String = "System.Int32"
Dim str_value As String = "47"
Dim theType As Type = Type.GetType(str_class)
Dim o As Object = (CType(str_value, IConvertible)).ToType(theType, System.Globalization.CultureInfo.InvariantCulture)
[/code]


thanks for your help in advance,

best regards, Daniel.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Create a Box, Arrow with properties from DataB
Reply #8 - Mar 23rd, 2006 at 4:14pm
Print Post  
Hi Daniel,

First the Type.GetType(str_class) doesn't seem to work, probably it expects the full type name there, including assembly specifiers. An easier way to get the type is

theType = fc.GetType().Assembly.GetType(str_class)

and it works fine in my test app. Then I couldn't get the conversion to work too, but Enum.Parse seems to do the job fine, e.g.:

o = System.Enum.Parse(theType, str_value);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint