473,508 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic creation of object during runtime

(Type your message here)

--------------------------------
From: murali pannala
i would want to create an object dynamically. i.e i hold my class name in a variable only.and by passing this variable can i create the object of the type (value which the variable holds)

eg :

dim str as string
str="active"

i wanna create an object of type active during runtime as the val of str can keep changing

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>saB0DWAvk0ylDKckkIv4mQ==</Id>
Nov 20 '05 #1
4 1428
"murali pannala via .NET 247" <an*******@dotnet247.com> schrieb

i would want to create an object dynamically. i.e i hold my class
name in a variable only.and by passing this variable can i create the
object of the type (value which the variable holds)

eg :

dim str as string
str="active"

i wanna create an object of type active during runtime as the val of
str can keep changing

System.Activator.CreateInstance
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Not easily possible, Ive seen this question asked before and there was a
solution, however, i seem to remember it was a rather convoluted answer.

OHM
"murali pannala via .NET 247" <an*******@dotnet247.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
(Type your message here)

--------------------------------
From: murali pannala
i would want to create an object dynamically. i.e i hold my class name in a variable only.and by passing this variable can i create the object of the
type (value which the variable holds)
eg :

dim str as string
str="active"

i wanna create an object of type active during runtime as the val of str can keep changing
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>saB0DWAvk0ylDKckkIv4mQ==</Id>

Nov 20 '05 #3
Thats the one!

Well Done - OHM
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"murali pannala via .NET 247" <an*******@dotnet247.com> schrieb

i would want to create an object dynamically. i.e i hold my class
name in a variable only.and by passing this variable can i create the
object of the type (value which the variable holds)

eg :

dim str as string
str="active"

i wanna create an object of type active during runtime as the val of
str can keep changing

System.Activator.CreateInstance
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
* murali pannala via .NET 247 <an*******@dotnet247.com> scripsit:
i would want to create an object dynamically. i.e i hold my class name
in a variable only.and by passing this variable can i create the object
of the type (value which the variable holds)


\\
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)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

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

Similar topics

9
3070
by: firegun9 | last post by:
Hello all, After looking for the solution for a while in the group, I know this is not possible in C++. So I just say my problme here. The input file is: dev1 1 1 dev2 0 0 0 6 There is a...
3
3397
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; ...
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
4
2023
by: Tom | last post by:
Hi .Net Professional : In recent , I starting to learn about dynamic call .net object in vb.net. Before, some IT people teach me use the following method and its work !! Dim asm As =...
0
2055
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
1
20530
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
6
2350
by: alf | last post by:
is there any way to tell the class the base class during runtime? a.
13
3019
by: DaTurk | last post by:
Hi, This is a question brought about by a solution I came up with to another question I had, which was "Dynamic object creation". So, I'm curious if you can dynamically cast an object. If you...
2
3426
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
0
7398
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...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.