Creating an Unknown Object

  • Thread starter Thread starter astroboy
  • Start date Start date
look at the overloaded Activator.CreateInstance method.
you can also use the vb6 CreateObject method
there should be some examples in the MSDN help for these methods..

hope this helps..
Imran.
 
* "astroboy said:
How do I create an object of unknown type
like this example do in Java
http://www.churchillobjects.com/c/11042b.html

\\\
Private Function CreateClassByName( _
ByVal PartialAssemblyName As String, _
ByVal QualifiedClassName As String _
) As Object
Return _
Activator.CreateInstance( _
[Assembly].LoadWithPartialName( _
PartialAssemblyName _
).GetType(QualifiedClassName) _
)
End Function
///

Usage:

\\\
Dim c As Control = _
DirectCast( _
CreateClassByName( _
"System.Windows.Forms", _
"System.Windows.Forms.Button" _
), _
Control _
)
With c
.Location = New Point(10, 10)
.Size = New Size(80, 26)
.Text = "Hello World"
End With
Me.Controls.Add(c)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top