473,395 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1661
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*****@hotmail.com> wrote in message
news:wZbSc.282915$XM6.153027@attbi_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******@bellsouth.net> wrote in message
news:%d****************@bignews4.bellsouth.net...
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*****@hotmail.com> wrote in message
news:bTiSc.284516$Oq2.99946@attbi_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
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...
0
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...
27
by: ajay | last post by:
Why would a new of object be created without assigning it to any of variable? new A; ??? tx
8
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...
4
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...
20
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 =...
3
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...
3
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...
37
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.