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

Creating an Unknown Object

P: n/a
How do I create an object of unknown type
like this example do in Java
http://www.churchillobjects.com/c/11042b.html
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <da****@ddadde.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
How do I create an object of unknown type
like this example do in Java
http://www.churchillobjects.com/c/11042b.html

Nov 20 '05 #2

P: n/a
* "astroboy" <da****@ddadde.com> scripsit:
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)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.