Solved

Basic Object assigning problem (Byval not working)

Posted on 2004-04-07
4
241 Views
Last Modified: 2010-04-17
Dear All,

I have Obj1 and Obj2 as objects of class1. When I access these 2 objects independently it works fine but when I say set Obj1=Obj2 it gets assigned by REF. So when I can Obj1's property Obj2's property also gets set.

Now I dont want this so I have written an function which accepts parameters as BYVAL and returns the objects which I again assigns to Obj1. Eg.


Function AssignByVal (Byval vdata as Object) as Object
   set AssignByVal = vdata
end sub

But this not works. It only works when I assign byval using piece - by piece method.
0
Comment
Question by:Shaileng
4 Comments
 

Accepted Solution

by:
Doknjas earned 25 total points
ID: 10780799
When you set an object reference to another object, both references point to the same object.  If you want to return a copy, then you have to do that yourself by implementing your own copy constructors - serialization will simplify this.

Passing the original object ByVal just ensures that the original object reference will not be pointing elsewhere after the method returns to the calling method.
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 25 total points
ID: 10782829
You need to implement a Clone method. See an article I wrote on the subject: http://www.utmag.com/July2003/Page8.asp
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 85
Microsoft C++ code failing in executable that worked 9 97
Base1 Encode/Decode 3 77
Help Required 2 29
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now