473,791 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referenced object versus copy of object

If I pass an object to another form via the new form's tag property, I want
to create an object exactly like it, with it's properties and all, but have
it be a copy of the object passed through, and not just a reference to the
object.

Example:

Public Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)

Dim obj as Object = Activator.Creat eInstance(Me.Ta g.GetType())
obj = Me.Tag

When I say that obj = Me.Tag, then it only provides a reference to the
object in the Tag property. How can I create an exact duplicate instead?

TIA,
-Jason
Mar 18 '06 #1
4 1441
Hi OpticTygre,

a way is to simply serialize the object in memory (don't need the
"Activator.Crea teInstance" stuff).

In addition, if it contains nonserialized members, you have to relink
them (can use those of the object being cloned). (If this is done on
large scale in complex applications you need to get organized, in
order not to miss any relink...)

Let me know if you need more help...

-tom

Mar 18 '06 #2
OpticTygre,

This is difficult to explain because there is no standard.

Most Copy methods are shalow copies. The pointers of its members are copied.
The CopyTo method is a copy method, however is not everywhere.
The Copy from a datatable and a dataset object is a real copy as well as the
GetChanges in that object.

To copy an object completely you can serialize and deserialize it.
Here a sample with an arraylist. (the class has to be serializable)

http://www.vb-tips.com/default.aspx?...c-61641f5c8d9d

Be aware that although this are few instructions it takes time.

I hope this helps,

Cor

"OpticTygre " <op********@ade lphia.net> schreef in bericht
news:G5******** *************** *******@adelphi a.com...
If I pass an object to another form via the new form's tag property, I
want to create an object exactly like it, with it's properties and all,
but have it be a copy of the object passed through, and not just a
reference to the object.

Example:

Public Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)

Dim obj as Object = Activator.Creat eInstance(Me.Ta g.GetType())
obj = Me.Tag

When I say that obj = Me.Tag, then it only provides a reference to the
object in the Tag property. How can I create an exact duplicate instead?

TIA,
-Jason

Mar 18 '06 #3
Actually I had in mind a binary serialization: I would like to try both
to see which one is faster (whithout trying,I would assume binary
should be better).

Actually this is a fundamental issue in programming, and as Cor has
sugested, it can take months to fully master all the subtleties.

Assume for instance you have an object which has the property (an
object) "Kind". Assume you have 100 of these objects stored in an
arraylist. Assume that there are only 5 kinds fo "Kind" objects which
are themseles stored in another arraylist, say "Kinds".

When you serialize and deserialize the arraylist with the 100 objects
and the arraylist with the 5 Kinds, you lose the referential equality
of the Kinds. You will have 100 objects each with its "Kind" and each
of these is a different reference from the 5 deserialized "Kinds" that
are in the arraylist od the Kinds. So you will need to relink them...

This is just one example. One really has to get well organized
(creating interfaces and precise rules to jerarchically restore
objects) to deal with that effectively in real world application...

Let me know if you compare the 2 types of serializations. ..

tom

Cor Ligthert [MVP] ha scritto:
OpticTygre,

This is difficult to explain because there is no standard.

Most Copy methods are shalow copies. The pointers of its members are copied.
The CopyTo method is a copy method, however is not everywhere.
The Copy from a datatable and a dataset object is a real copy as well as the
GetChanges in that object.

To copy an object completely you can serialize and deserialize it.
Here a sample with an arraylist. (the class has to be serializable)

http://www.vb-tips.com/default.aspx?...c-61641f5c8d9d

Be aware that although this are few instructions it takes time.

I hope this helps,

Cor

"OpticTygre " <op********@ade lphia.net> schreef in bericht
news:G5******** *************** *******@adelphi a.com...
If I pass an object to another form via the new form's tag property, I
want to create an object exactly like it, with it's properties and all,
but have it be a copy of the object passed through, and not just a
reference to the object.

Example:

Public Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)

Dim obj as Object = Activator.Creat eInstance(Me.Ta g.GetType())
obj = Me.Tag

When I say that obj = Me.Tag, then it only provides a reference to the
object in the Tag property. How can I create an exact duplicate instead?

TIA,
-Jason


Mar 18 '06 #4
Yeah, and actually, what makes it difficult is that I can't guarantee these
objects to be Serializable, let alone all properties, variables, etc...
(What if the object is serializable but a field marked as nonserializable ,
or if the object isn't serializable at all?)

-Jason

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl...
OpticTygre,

This is difficult to explain because there is no standard.

Most Copy methods are shalow copies. The pointers of its members are
copied.
The CopyTo method is a copy method, however is not everywhere.
The Copy from a datatable and a dataset object is a real copy as well as
the GetChanges in that object.

To copy an object completely you can serialize and deserialize it.
Here a sample with an arraylist. (the class has to be serializable)

http://www.vb-tips.com/default.aspx?...c-61641f5c8d9d

Be aware that although this are few instructions it takes time.

I hope this helps,

Cor

"OpticTygre " <op********@ade lphia.net> schreef in bericht
news:G5******** *************** *******@adelphi a.com...
If I pass an object to another form via the new form's tag property, I
want to create an object exactly like it, with it's properties and all,
but have it be a copy of the object passed through, and not just a
reference to the object.

Example:

Public Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)

Dim obj as Object = Activator.Creat eInstance(Me.Ta g.GetType())
obj = Me.Tag

When I say that obj = Me.Tag, then it only provides a reference to the
object in the Tag property. How can I create an exact duplicate instead?

TIA,
-Jason


Mar 18 '06 #5

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

Similar topics

30
13757
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with this? I would think that the library function std::copy would perform optimally, as it is a library function, and therefore the writers of this function would know best how to optimize it ... but some tests seem to indicate that my pointer copy...
1
1495
by: Jimi | last post by:
(Sorry for the repost, but I thought maybe I'd have better luck this time) I'm working on a utility to provide an overview of one's .NET projects and one of the things I want to display is detailed information about what each project references, whether it is assemblies in the GAC or non-GAC assemblies or other .NET projects. From the project file I can get the assembly names of all assemblies referenced by a project, including other...
3
1398
by: Axel | last post by:
HI I want to reference code in an external Access Database, and refresh that database (by downloading from network location). Do I need to bootstrap? Or is it possible (during autorun) overwriting the referenced database? Currently the Customer uses one shared referenced Access Database (which is about 80 MB) which is impossible to update because its referenced to a network path from around 25 to 30 users. I want to
1
3199
by: Kenny D | last post by:
Sample input XML... <Publication> <FilingMetadata> <Id>38EA51240E6643208DB1B6D52F779A82</Id> <Cycle>BC</Cycle> </FilingMetadata> <PublicationComponent Role="Main" MediaType="Text"> <TextContentItem> <Language>en-us</Language>
13
5022
by: blangela | last post by:
I have decided (see earlier post) to paste my Word doc here so that it will be simpler for people to provide feedback (by directly inserting their comments in the post). I will post it in 3 parts to make it more manageable. Below is a draft of a document that I plan to give to my introductory C++ class. Please note that I have purposely left out any mention of safety issues in the ctors which could be resolved thru some combination...
2
5334
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
6
4140
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected functions of another (same type) - but not via a base class pointer.... I've checked the FAQs, Meyers etc but nothing obvious I can find explains it.
1
2581
by: cnixuser | last post by:
Hello, I am currently working on an ASP.NET web application. When I compile my code behind the page, I do not get any errors ;however, when I attempt to view my code in a browser I get the error that is the title of this post. I am going to include a copy of my code behind the page, and my .aspx file code, can anyone help me out here? I am using Visual Studio.NET 2003, and my code behind the page is written in C#. Here is the error as it...
2
1854
by: Veloz | last post by:
Hiya My question is whether or not you should associated related objects in your software using a scheme of id's and lookups, or wether objects should actually hold actual object references to objects they are associated with. For example, lets say you are modelling studen ratings of teachers. Let's say your applications needs to analyze these ratings for teachers and is provided a data file. In this data file the teachers all have...
0
10419
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...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9987
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
9023
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...
0
6770
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
5424
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
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.