473,804 Members | 3,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning one object to another

I came across something by accident; assigning one object to another (as in
object1 = object2) allows me to "work on" object2 just like it was object1.
For instance, in order to be able to reference a textbox on form1 I created
a textbox at module level called PassTextBox and assigned the original
textbox to it (textbox1 = PassTextBox) in Form1's load code. I was planning
on just using this as a "hold" area and when I got back into Form1 I could
assign PassTextBox back to textbox1. But I found out that whatever I did to
PassTextBox (such as changing the .text property) WAS ALREADY DONE IN
textbox1! So this makes me think there's something inherent in the object
that I can't see (or am not aware of) that contains an address (pointer).
Are the two textboxes two separate entities that just "point" to the same
place? I see this could open up a lot of possibilities but also a lot of
potential problems. How do you make a true "copy" of an object (so that
changing a property in one doesn't affect the other)? It's almost like the
assign is working ByRef instead of ByVal.

--
Thanks,
Ricky W. Hunt
freendeed
Nov 21 '05 #1
3 1673
you are ending up with 2 names for the same object
remember - object variables are reference types

to avoid this (if you need to)
create a different object and just copy the values into the new object -
being careful not to make the same mistake on member objects of the object
you're copying -
or - look up the clone method

"Ricky W. Hunt" <rh*****@hotmai l.com> wrote in message
news:wZbSc.2829 15$XM6.153027@a ttbi_s53...
I came across something by accident; assigning one object to another (as in object1 = object2) allows me to "work on" object2 just like it was object1. For instance, in order to be able to reference a textbox on form1 I created a textbox at module level called PassTextBox and assigned the original
textbox to it (textbox1 = PassTextBox) in Form1's load code. I was planning on just using this as a "hold" area and when I got back into Form1 I could
assign PassTextBox back to textbox1. But I found out that whatever I did to PassTextBox (such as changing the .text property) WAS ALREADY DONE IN
textbox1! So this makes me think there's something inherent in the object
that I can't see (or am not aware of) that contains an address (pointer).
Are the two textboxes two separate entities that just "point" to the same
place? I see this could open up a lot of possibilities but also a lot of
potential problems. How do you make a true "copy" of an object (so that
changing a property in one doesn't affect the other)? It's almost like the
assign is working ByRef instead of ByVal.

--
Thanks,
Ricky W. Hunt
freendeed

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/30/2004
Nov 21 '05 #2
"Hal Rosser" <hm******@bells outh.net> wrote in message
news:%d******** ********@bignew s4.bellsouth.ne t...
you are ending up with 2 names for the same object
remember - object variables are reference types
That's kind of what I had deduced. Thanks for claryfing. So if you had 100
such objects they'd really only take up the space of one?

to avoid this (if you need to)
create a different object and just copy the values into the new object -
being careful not to make the same mistake on member objects of the object
you're copying -
or - look up the clone method


thanks.
Nov 21 '05 #3
"Ricky W. Hunt" <rh*****@hotmai l.com> wrote in message
news:bTiSc.2845 16$Oq2.99946@at tbi_s52...
That's kind of what I had deduced. Thanks for claryfing. So if you had 100
such objects they'd really only take up the space of one?


Yep. Technically, the space of one and the space of [up to] 100 pointers to
it. In general, "reference type" means "variable is only a pointer". A
side effect of this is that ByRef and ByVal are pretty much the same for
objects and/or reference types. ByVal will still make a copy, as you would
expect, but it is only copying the pointer, not the entire object.

Some more explanation:

http://msdn.microsoft.com/library/de...gmechanism.asp

Best Regards,

Andy
Nov 21 '05 #4

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

Similar topics

37
3982
by: Dave | last post by:
Hello all, Please consider the code below. It is representative of a problem I am having. foo_t needs to contain a bar_t which is a class without a copy constructor or operator=. It is not within my control to change bar_t. Furthermore, I need to be able to update the contained bar_t at runtime (hence the set_bar() method seen below).
0
1602
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated classes) with the XML data in element nodes or attributes - assemble the objects so they are contained in their parent - add the resulting object to an arrayList The problem I’m having is that I am not sure how to go about assigning an object to...
27
2003
by: ajay | last post by:
Why would a new of object be created without assigning it to any of variable? new A; ??? tx
8
1704
by: Ricardo Sta. Rita | last post by:
Hello people, We have been dealing with for a long time now. It's a bit weird for a newcomer like us so we decided to ask the geniuses here. C# doesn't seem to be assigning values, consider the lines of codes below: ------------------------------------------------ using Sem = semantics.SemanticsProcessingClass; ------------------------------------------------
4
1258
by: Jon | last post by:
This seems strange, but maybe there's some basic concept I'm missing. When I assign one class member to another, any methods that are applied to one are applied to both variables.I can't get the code below to work (display sum, product and quotient) without re-initializing z1 each time. What's the problem here? Dim z0 As Complex = New Complex(CDbl(Me.TextBox1.Text), CDbl(Me.TextBox2.Text)) Dim z1 As Complex = New...
20
7017
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
3
1865
by: teddarr | last post by:
I have an assignment I am working on that requires me to declare a new object (object 5, r5)and initialize it by assigning it a previous object (object 2, Rectangle r2(7.1, 3.2);). How do I do that? The class that does the work is names Rectangle. Here is the code for main so far. #include "Rectangle.h" #include <iomanip>
3
2217
by: Froefel | last post by:
Hi group I am creating a web application that uses a simple DAL as an ObjectDataSource. To retrieve data from the database, I use a DataReader object from which I then assign the various fields to properties in an object, like so: in the DB, the fields are defined as follows: ProjectID int NOT NULL
37
2679
by: miken32 | last post by:
In PHP, if a function returns an array it's fairly common to capture its return values like this: <?php list($foo, $bar, $baz) = some_function_that_return_an_array(); ?> In Javascript, would the equivalent (acceptable) code be this? = some_function_that_return_an_array();
0
10567
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
10310
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
10074
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
9138
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
6847
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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 we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
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.