473,473 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Howto create new object, of type of other object?

Hello,

question regarding the following code:

Public Class MyCol
Inherits System.Collections.SortedList
....
Public Sub MyFunction( objMyClass As MyClass )

End Sub
....
End Class

How is it possible to create a NEW instance of the object MyClass inside
MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )

Thanks.
Nov 21 '05 #1
6 3748
Qwert,
How is it possible to create a NEW instance of the object MyClass inside
MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )

You mean
Dim objNew as New TheMyClass

You cannot instance an object, that goes only for classes.
(Not to mixup that object is a class, however an object is an instanced
class)

I just am guessing that this was the question.

Cor
Nov 21 '05 #2
Yeah, no, what I mean is this:

MyClass
Public Function GetNew() As MyClass
Return New MyClass()
End Function
End MyClass

now, somewhere else I can do:

Public Sub MyFunction( objObject As Object)
Dim objObject1 As Object = objObject.GetNew()
Dim objObject2 As Object = objObject.GetNew()
End Sub

I want to do this, but without writing the GetNew() function for MyClass.
And MyFunction() does not know what type objObject will be.
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:uA*************@TK2MSFTNGP12.phx.gbl...
Qwert,
How is it possible to create a NEW instance of the object MyClass inside
MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )

You mean
Dim objNew as New TheMyClass

You cannot instance an object, that goes only for classes.
(Not to mixup that object is a class, however an object is an instanced
class)

I just am guessing that this was the question.

Cor

Nov 21 '05 #3
"Qwert" <no**@nosp.com> schrieb:
How is it possible to create a NEW instance of the object MyClass inside
MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )


Take a look at 'Activator.CreateInstance'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4


Dim z As Object = Activator.CreateInstance(y.GetType())

"Qwert" <no**@nosp.com> wrote in message
news:mq********************@casema.nl...
Yeah, no, what I mean is this:

MyClass
Public Function GetNew() As MyClass
Return New MyClass()
End Function
End MyClass

now, somewhere else I can do:

Public Sub MyFunction( objObject As Object)
Dim objObject1 As Object = objObject.GetNew()
Dim objObject2 As Object = objObject.GetNew()
End Sub

I want to do this, but without writing the GetNew() function for MyClass.
And MyFunction() does not know what type objObject will be.
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:uA*************@TK2MSFTNGP12.phx.gbl...
Qwert,
How is it possible to create a NEW instance of the object MyClass inside
MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )

You mean
Dim objNew as New TheMyClass

You cannot instance an object, that goes only for classes.
(Not to mixup that object is a class, however an object is an instanced
class)

I just am guessing that this was the question.

Cor


Nov 21 '05 #5
Quert,

You mean simple this?

Dim objObject1 As Object = New Mycl
Dim objObject2 As Object = New Mycl

(I would not use myclass in samples that is a reserved word)

I hope this helps,

Cor
Nov 21 '05 #6
Yes, great, that's it. Thanks all.

"Robin Tucker" <id*************************@reallyidont.com> schreef in
bericht news:d7*******************@news.demon.co.uk...


Dim z As Object = Activator.CreateInstance(y.GetType())

"Qwert" <no**@nosp.com> wrote in message
news:mq********************@casema.nl...
Yeah, no, what I mean is this:

MyClass
Public Function GetNew() As MyClass
Return New MyClass()
End Function
End MyClass

now, somewhere else I can do:

Public Sub MyFunction( objObject As Object)
Dim objObject1 As Object = objObject.GetNew()
Dim objObject2 As Object = objObject.GetNew()
End Sub

I want to do this, but without writing the GetNew() function for MyClass.
And MyFunction() does not know what type objObject will be.
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:uA*************@TK2MSFTNGP12.phx.gbl...
Qwert,

How is it possible to create a NEW instance of the object MyClass
inside MyFunction (without adding functionality to MyClass)?
Something like:

Dim objNew As Object = CreateNewInstance( objMyClass )

You mean
Dim objNew as New TheMyClass

You cannot instance an object, that goes only for classes.
(Not to mixup that object is a class, however an object is an instanced
class)

I just am guessing that this was the question.

Cor



Nov 21 '05 #7

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

Similar topics

4
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or...
0
by: joe mamma | last post by:
I know it works for basic widows form components. . . Similar approach can be applied for other controls if this doesn't work . . . Typical Usage: ============================= ArrayList...
4
by: Irena | last post by:
Hi all again, Maybe, I'd better try to do this: How can it programmatically get/return the "Row source" or Rowsource property of a generic Table in a generic Access 2K database??? I found...
0
by: ATS | last post by:
HOWTO Make a UserControl deploy an embedded resource. Please help, I need to embed an EXE into a C# UserControl that is run from script in an HTML web page as such: <html> <object...
3
by: ATS | last post by:
HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary. Below is code that I want to be able to use simple LoadLibrary\GetProcAddress\FreeLibrary technqiues on. I've used the code that was...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
6
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
12
by: Stef Mientki | last post by:
In the example below, "pin" is an object with a number of properties. Now I want 1- an easy way to create objects that contains a number of these "pin" 2- an multiple way to access these "pin",...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.