Solved

Basic Object assigning problem (Byval not working)

Posted on 2004-04-07
4
239 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
Comment Utility
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 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 25 total points
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

9 Experts available now in Live!

Get 1:1 Help Now