
Reflection Question How to Call a Methode of a Member without Createing a new instance
I have following Situation
I have one Class which has 3 Objects, the 3 Objects defined by Class 2
Public Class Class1
Public ChildClass1 As New Class2()
Public ChildClass2 As New Class2()
Public ChildClass3 As New Class2()
End Class
Here is Class 2:
Public Class Class2
Public Sub Test()
MsgBox("Hello")
End Sub
End Class
The I have Code (in a Form e.g.) where I Created a Object of Class1
and then call the Methode "Test" from the Class to via Class1.
Public Class Form1
Private Sub Button1_Click(..........
Dim vlob_MyObject As New Class1()
vlob_MyObject.ChildClass1.Test()
End Sub
End Class
Only at Runtime I know which of the Three Child Objects I want to Call.
vlob_MyObject.ChildClass1.Test()
or
vlob_MyObject.ChildClass2.Test()
or
vlob_MyObject.ChildClass3.Test()
I get the Name of the Object via a String "ChildClass1"
How can I do this ?
All Samples which I saw with Reflection make an new Instance of a Class
but in this Case I allread have Instances of the Child Objects and won't
Create new Objects
because I need the Information the Objects allread have.
Thanx for any Adwise
Micha