Hi,
how can I create an instance (object) of a class (form) if I only know the
classname (VB.NET 1.0)?
I need to do this in a complex app where jobs consist of parts. Each part's
data is saved in a separate database table. For the parts, the form's class
name is saved in a data table, so that I know which form to use. As this is
a string, I need to be able to create the form by it's name (like
CreateObject() does for COM objects).
--
Any help gladly appreciated!
Rene Mansveld
Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o) 6 2387
take a look at the Activator.CreateInstance method in the System.Reflection
namespace.
hope that helps..
Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Hi,
how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved in a separate database table. For the parts, the form's class name is saved in a data table, so that I know which form to use. As this is a string, I need to be able to create the form by it's name (like CreateObject() does for COM objects).
-- Any help gladly appreciated!
Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
Thanks for the quick answer!
Unfortunately I couldn't get this to work, and according to the help, this
will create an instance of a Type.
I tried the Activator.CreateInstance(Nothing, "Auftrag") call, but I got
this exception:
A non handled exception of type 'System.TypeLoadException' occured in
mscorlib.dll.
Extra info: The type Auftrag in the assembly ..., Version=0.3.1783.15723,
Culture=neutral, PublicKeyToken=null could not be loaded.
(translated from german)
Any ideas anyone?
--
Rene Mansveld
Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Imran Koradia" <no****@microsoft.com> schrieb im Newsbeitrag
news:uH**************@TK2MSFTNGP12.phx.gbl... take a look at the Activator.CreateInstance method in the
System.Reflection namespace.
hope that helps.. Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Hi,
how can I create an instance (object) of a class (form) if I only know
the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved in a separate database table. For the parts, the form's class name is saved in a data table, so that I know which form to use. As this is a string, I need to be able to create the form by it's name (like CreateObject() does for COM objects).
-- Any help gladly appreciated!
Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
It's solved now!
I got an answer from the german newsgroup from Jürgen Luhr which did it.
It is done through Reflexion:
'<deklaration code>
Imports System.Reflexion
'<routine code>
Dim t As Type = Type.GetType("<Namespace>.<Class>")
Dim c As ConstructorInfo = t.GetConstructor(Type.EmptyTypes)
Dim o As Object = c.Invoke(Nothing)
'Now o holds the instance of the class
--
Hope this helps ...
Rene Mansveld
Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> schrieb im Newsbeitrag
news:Op**************@TK2MSFTNGP12.phx.gbl... Thanks for the quick answer!
Unfortunately I couldn't get this to work, and according to the help, this will create an instance of a Type. I tried the Activator.CreateInstance(Nothing, "Auftrag") call, but I got this exception: A non handled exception of type 'System.TypeLoadException' occured in mscorlib.dll. Extra info: The type Auftrag in the assembly ..., Version=0.3.1783.15723, Culture=neutral, PublicKeyToken=null could not be loaded. (translated from german)
Any ideas anyone?
-- Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Imran Koradia" <no****@microsoft.com> schrieb im Newsbeitrag news:uH**************@TK2MSFTNGP12.phx.gbl... take a look at the Activator.CreateInstance method in the System.Reflection namespace.
hope that helps.. Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... Hi,
how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved in a separate database table. For the parts, the form's class name is saved in a data table, so that I know which form to use. As
this is a string, I need to be able to create the form by it's name (like CreateObject() does for COM objects).
-- Any help gladly appreciated!
Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
Correction: Reflexion should be Reflection ;o)
--
Hope this helps ...
Rene Mansveld
Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> schrieb im Newsbeitrag
news:uC*************@TK2MSFTNGP11.phx.gbl... It's solved now!
I got an answer from the german newsgroup from Jürgen Luhr which did it. It is done through Reflexion:
'<deklaration code> Imports System.Reflexion
'<routine code> Dim t As Type = Type.GetType("<Namespace>.<Class>") Dim c As ConstructorInfo = t.GetConstructor(Type.EmptyTypes) Dim o As Object = c.Invoke(Nothing) 'Now o holds the instance of the class
-- Hope this helps ...
Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> schrieb im
Newsbeitrag news:Op**************@TK2MSFTNGP12.phx.gbl... Thanks for the quick answer!
Unfortunately I couldn't get this to work, and according to the help,
this will create an instance of a Type. I tried the Activator.CreateInstance(Nothing, "Auftrag") call, but I got this exception: A non handled exception of type 'System.TypeLoadException' occured in mscorlib.dll. Extra info: The type Auftrag in the assembly ...,
Version=0.3.1783.15723, Culture=neutral, PublicKeyToken=null could not be loaded. (translated from german)
Any ideas anyone?
-- Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Imran Koradia" <no****@microsoft.com> schrieb im Newsbeitrag news:uH**************@TK2MSFTNGP12.phx.gbl... take a look at the Activator.CreateInstance method in the System.Reflection namespace.
hope that helps.. Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... > Hi, > > how can I create an instance (object) of a class (form) if I only
know the > classname (VB.NET 1.0)? > I need to do this in a complex app where jobs consist of parts. Each > part's > data is saved in a separate database table. For the parts, the
form's > class > name is saved in a data table, so that I know which form to use. As this > is > a string, I need to be able to create the form by it's name (like > CreateObject() does for COM objects). > > -- > Any help gladly appreciated! > > Rene Mansveld > Spider IT - Germany > www.Spider-IT.de / www.Spider-IT.net > > Please reply to the newsgroup(s) :o) > >
Well - its the same with Activator.CreateInstance. You get the type object
from the namespace and class name and pass in the type object to the method:
Dim t As Type = Type.GetType("<Namespace>.<Class>")
Dim frm As Object = Activator.CreateInstance(t)
DirectCast(frm, Form).Show()
Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message
news:uC*************@TK2MSFTNGP11.phx.gbl... It's solved now!
I got an answer from the german newsgroup from Jürgen Luhr which did it. It is done through Reflexion:
'<deklaration code> Imports System.Reflexion
'<routine code> Dim t As Type = Type.GetType("<Namespace>.<Class>") Dim c As ConstructorInfo = t.GetConstructor(Type.EmptyTypes) Dim o As Object = c.Invoke(Nothing) 'Now o holds the instance of the class
-- Hope this helps ...
Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> schrieb im
Newsbeitrag news:Op**************@TK2MSFTNGP12.phx.gbl... Thanks for the quick answer!
Unfortunately I couldn't get this to work, and according to the help,
this will create an instance of a Type. I tried the Activator.CreateInstance(Nothing, "Auftrag") call, but I got this exception: A non handled exception of type 'System.TypeLoadException' occured in mscorlib.dll. Extra info: The type Auftrag in the assembly ...,
Version=0.3.1783.15723, Culture=neutral, PublicKeyToken=null could not be loaded. (translated from german)
Any ideas anyone?
-- Rene Mansveld Spider IT - Germany www.Spider-IT.de / www.Spider-IT.net
Please reply to the newsgroup(s) :o)
"Imran Koradia" <no****@microsoft.com> schrieb im Newsbeitrag news:uH**************@TK2MSFTNGP12.phx.gbl... take a look at the Activator.CreateInstance method in the System.Reflection namespace.
hope that helps.. Imran.
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... > Hi, > > how can I create an instance (object) of a class (form) if I only
know the > classname (VB.NET 1.0)? > I need to do this in a complex app where jobs consist of parts. Each > part's > data is saved in a separate database table. For the parts, the
form's > class > name is saved in a data table, so that I know which form to use. As this > is > a string, I need to be able to create the form by it's name (like > CreateObject() does for COM objects). > > -- > Any help gladly appreciated! > > Rene Mansveld > Spider IT - Germany > www.Spider-IT.de / www.Spider-IT.net > > Please reply to the newsgroup(s) :o) > >
"Rene Mansveld" <R.********@TAKETHISOUT.Spider-IT.de> schrieb: how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)?
\\\
Private Function CreateClassByName( _
ByVal PartialAssemblyName As String, _
ByVal QualifiedClassName As String _
) As Object
Return _
Activator.CreateInstance( _
[Assembly].LoadWithPartialName( _
PartialAssemblyName _
).GetType(QualifiedClassName) _
)
End Function
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: me |
last post by:
I have a Class Library that contains a Form and several helper classes. A
thread gets created that performs processing of data behind the scenes and
the Form never gets displayed (it is for debug...
|
by: SamIAm |
last post by:
Hi am creating a email application that needs to mail out a very large
amount of emails. I have created a multithreaded c# application that using
message queuing. I have created a threadpool of 5...
|
by: Bill D |
last post by:
In a simple Windows forms application, the main form is
called Form1. Within this form's class, I refer to the
the running instance of this main class as "this" as in
this.Text = "NEW TEXT"
I...
|
by: Patrick |
last post by:
I'm working on a contact management application, and need a hand with one
aspect...
Here's what I want to create:
------------------------------------
A form split into two parts. There is a...
|
by: Clinton Pierce |
last post by:
I can create a delegate like this, and everything works fine:
class Foo
{
private delegate void NextPanel();
private NextPanel myself;
// And later in a method
private void EffStart()
{
|
by: wu jianhua |
last post by:
hi.
If I have a form, like FrmAbout, can I create a form instance only with a
string "FrmAbout"?
not like : Form frm = new FrmAbout();
I want the code : Form frm = createInstance( "FrmAbout" );...
|
by: max |
last post by:
Hello,
I am a newbye, and I'm trying to write a simple application.
I have five tables with three columns; all tables are identical; I need to
change some data in the first table and let VB...
|
by: etuncer |
last post by:
Hello All,
I have Access 2003, and am trying to build a database for my small
company. I want to be able to create a word document based on the data
entered through a form. the real question is...
|
by: bharathreddy |
last post by:
Before going to that i want to say few thing on serialization :
Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |