473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to code the creation of object when the class is not known?

Normally, to create an object instance based on a specific class, we can do
this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3. The
variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass

Jul 18 '07 #1
4 1152
"Peter" <Pe***@discussions.microsoft.comschrieb
Normally, to create an object instance based on a specific class, we
can do this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3.
The variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass

http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx

In particular:
http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
(search for "CreateInstance")
Armin
Jul 18 '07 #2
Thanks Armin. I hope I can understand it (reflection) since I'm new to
..net. I hope MS has a webcast to explain it.

"Armin Zingler" wrote:
"Peter" <Pe***@discussions.microsoft.comschrieb
Normally, to create an object instance based on a specific class, we
can do this.

Dim someObj As Object
someObj = New Class

However,I want to create an object instance based on a variable or
something. For example, I have 3 classes: Class1, Class2, Class3.
The variable dynamicClass can be equal to any of the 3 classes

Dim someObj As Object
someObj = New dynamicClass


http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx

In particular:
http://msdn2.microsoft.com/en-us/library/k3a58006.aspx
(search for "CreateInstance")
Armin
Jul 19 '07 #3
"Peter" <Pe***@discussions.microsoft.comschrieb
Thanks Armin. I hope I can understand it (reflection) since I'm
new to .net. I hope MS has a webcast to explain it.
Do you really need it? I mean, a class name in a variable. What are you
trying to accomplish?
Armin

Jul 19 '07 #4
Hi Armin,

One example is that I have 2 windows forms with the same name but in
different path. I want to create an instance of the form but the class may
be one of 2 forms depending on some conditions.


"Armin Zingler" wrote:
"Peter" <Pe***@discussions.microsoft.comschrieb
Thanks Armin. I hope I can understand it (reflection) since I'm
new to .net. I hope MS has a webcast to explain it.

Do you really need it? I mean, a class name in a variable. What are you
trying to accomplish?
Armin

Jul 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Richard | last post by:
Hi all, I am looking for some help on understanding the overhead associated with object creation in Java. I am writing an application where I have written a class to encapsulate some text...
6
by: Andre Meyer | last post by:
Hi all I have been searching everywhere for this, but have not found a solution, yet. What I need is to create an object that is an instance of a class (NOT a class instance!) of which I only...
22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
6
by: | last post by:
I have a class with overloading operator new. (Because, if an identical object exists, return a pointer to existed object instead of a new pointer) It has no sense (it is dangerous) to allocate an...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
3
by: John Ratliff | last post by:
When I dereference a pointer, does it make a copy of the object? Say I had a singleton, and wanted an static method to retrieve it from the class. class foo { private: static foo *bar; ...
2
by: Mark Sisson | last post by:
I'd like to instantiate a variable but the exact class is not known at compile time. In my specific application, I'm reading a message off of an socket and interogating the first part of the...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.