Reflection

06/09/2005 - 22:39 por Buho | Informe spam
Salu2,

Tengo un problema de reflection con FieldInfo.Setvalue. En el codigo
siguiente( es pequeñito :) ) en la linea donde trata de setear el
valor lanza esta excepcion:Message "Object type cannot be converted to
target type." String...

Public Function CargarReflectedForm(ByVal PATH As String, ByVal
classname As String, ByRef frm As Form)
Dim a As [Assembly] = [Assembly].LoadFrom(PATH)
Dim mytype As Type
Dim tran As Object
Dim prop As Object

Dim f As Form
'Get the type to use.
mytype = a.GetType(classname)
tran = Activator.CreateInstance(mytype)

Dim finfo() As FieldInfo
finfo = mytype.GetFields(BindingFlags.Instance Or
BindingFlags.Public)

Dim sOut As String()
ReDim sOut(fInfo.GetLength(0) - 1)
For i As Integer = 0 To finfo.GetLength(0) - 1
If finfo(i).Name = "DBLX" Then
finfo(i).SetValue(tran, DBLX)
End If
If finfo(i).Name = "DBL" Then
finfo(i).SetValue(tran, DBL)
End If
If finfo(i).Name = "PARAMETERSENV" Then
finfo(i).SetValue(tran, PARAMETERSENV)
End If
If finfo(i).Name = "SAMB" Then
finfo(i).SetValue(tran, SAMB)
End If
Next
frm = tran
End Function

Gracias de antemano...

Preguntas similare

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP VB]
07/09/2005 - 04:20 | Informe spam
¿Los valores que pasas son del mismo tipo que los campos que quieres setear?

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
http://mvp.support.microsoft.com/pr...4EF5A4191C
Respuesta Responder a este mensaje
#2 Buho
07/09/2005 - 16:16 | Informe spam
Si ...son del mismo tipo, no encontre mejor solucion que referenciar en
ambos programas un mismo assembly con estos tipos dentro, pero ahora me
lanza un error de Error creating window handle...no entiendo porque si
uso Activator.createinstance() me parece que al asignar el form al de
salida no lo puede copiar transparentemente.

El objetivo de esta funcion es devolver un formulario para que en otra
funcion el principal lo haga child, incluso he probado hacer que en
esta misma funcion lo haga child y me lanzo:

tran.mdiparent = prinfrm
tran.show()

Message "Exception has been thrown by the target of an


invocation."
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida