473,799 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sub(Thing as Object) {thing = new Thing.GetType} ?

Hello,
Sorry for polluting the VB newsgroup with curly brackets, but I couldn't
think how to get that question onto one line otherwise.
Anyway, I'm trying to write a Sub, or Function which takes an object as an
input and then creates a new object of the same type using that class'
constructor.
VB isn't currently liking any of my attempts, but the general idea is to
have:

Private Function NewInterfaceObj ectArray(ByVal InterfaceObject As
Object(), ByVal defaultValue As Integer) As InterfaceObject Class()
InterfaceObject = New InterfaceObject .GetType
Return InterfaceObject
End Function
That's a bit messy, even for pseudocode, but I think you'll get the idea..

I guess this is a bit of a weird question, but it's mostly because the
idea intrigued me while I was writing a long constructor for an object
made of object arrays, which were all interfaces onto a single object
type. I'm *sure* there was a good reason for coding that at the time...

Anyway, I can get round the problem, but I'm interested in whether the
language supports the idea of the function I'm asking about, and the
question seems to be too obscure for google (or my use of google) to cope
with.

KF
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Sep 22 '06 #1
1 963
"Kristian Frost" <kf****@gmail.c omschrieb:
>Sorry for polluting the VB newsgroup with curly brackets, but I couldn't
think how to get that question onto one line otherwise.
Anyway, I'm trying to write a Sub, or Function which takes an object as an
input and then creates a new object of the same type using that class'
constructor.
Obtain the type of the object passed to the method by calling its 'GetType'
method. Then pass the type to 'Activator.Crea teInstance' to create an
instance of the type.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 22 '06 #2

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

Similar topics

44
2468
by: Steven T. Hatton | last post by:
This may seem like such a simple question, I should be embarrassed to ask it. The FAQ says an object is "A region of storage with associated semantics." OK, what exactly is meant by "associated semantics"? What, if any, associated semantics are shared by all objects? That part seems to go beyond the FAQ. Does anybody know of a resource that discusses (focuses on) this topic? -- p->m == (*p).m == p.m
3
4754
by: Jenni | last post by:
Hi, my simple solution is not so simple. I have done a bit of VB programming, and am now tasked with trying to make access work using VBA, and battling my butt off. This probably has a really simple solution, which right now eludes me. The code is below, and the error message I get is this "No Value given for one or more required parameters". sClinic is picking up the string from a combo box, and this does work cos the message box tosses...
5
8874
by: Lars Moastuen | last post by:
Hi! I'm currently playing around with a project where I need to know if an object (any object) has been altered since last check. I need this to know when an object needs to be saved... My idea was to represent the object as a byte-array and then make a MD5-hash out of that byte (not very efficient though - but that won't really be a big problem here)... I guess that works fine as long as the object I need to check for updates doesn't...
1
2106
by: Sam Fields | last post by:
I have been wrestling with this code for about 2 weeks now. My goal is to create a table for formatting purposes. I want to standardize it as a webcontrol. I want all of the content to persist as top-level controls so that they are visible to the asp.net designer -- PersistChildren(true). The code works fine for run-time, but will not call AddParsedSubObject for design-time. If the content is literal only, it will add the parsed sub...
4
4173
by: craig | last post by:
During construction of an object "parent", if you create a subobject that stores a pointer to the parent (through the "this" pointer), will that pointer be valid when the subobject is later called? class Parent { Parent::Parent() { child = new Child( this) }; Child *child; };
0
972
by: bradtwurst | last post by:
Hello all, I have a webservice that I am calling via wsdl.exe generated code that is missing sub-objects when the soaphttpclientprotocol.invoke method is called. The basic layout is <Envelope> <Header/>
2
5926
by: chris fellows | last post by:
In VS2005 (C#) I want to set the properties of an object dynamically at runtime from an XML configuration file but without having to know the property name when writing the code. The properties are user-defined classes so I need to be able to iterate through the properties of each sub-object and set the property accordingly. For example, Instead of having to write the code MyObject.SubObjectOne.MyStringProperty = "Some text" I will...
8
1498
by: Anand | last post by:
I am trying to implement some kind of object inheritance. Just like one class can extend from another, I want to do the same on objects dynamically. I just thought that I can share my excitement here. Suppose there are classes A and B and their instances a and b. class A: def foo(self): self.say('foo')
23
3152
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object model: that most OO features are not available for class object design without loss of POD-ness. So, I'm more than leaning toward "bad" because of the limitations and
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.