473,388 Members | 1,215 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,388 software developers and data experts.

Strange behaviour on ByVal parameter ???

Dear all,

I have really strange behviour when passing an object to a
function by value:

if I create a new object of myClass from the main
application as follow:

myObj = new (ObjSource)

then the instance is creted on a separate assambly an
reach the code of the constructor of myClass
public sub new (byval obj as object)

.....
....

' here I try to channge some object value
obj.name ="test"
end sub

At this time when the object is created and I return to
the calling point in my main application , the object is
also modifed in the main application, and it should be not
as it is pass by value to the constructo of myClass !!

What did I miss here?

thnaks for your information
regards
Serge
Jul 21 '05 #1
3 1095
you're passing an object, so its "pointer" is passed by value. the
object itself isn't copied, so the changes you make to the object remain.

there's a reason "reference types" are so called - they're always passed
by reference.

serge calderara wrote:
Dear all,

I have really strange behviour when passing an object to a
function by value:

if I create a new object of myClass from the main
application as follow:

myObj = new (ObjSource)

then the instance is creted on a separate assambly an
reach the code of the constructor of myClass
public sub new (byval obj as object)

.....
....

' here I try to channge some object value
obj.name ="test"
end sub

At this time when the object is created and I return to
the calling point in my main application , the object is
also modifed in the main application, and it should be not
as it is pass by value to the constructo of myClass !!

What did I miss here?

thnaks for your information
regards
Serge


Jul 21 '05 #2
Thnaks so much for your answer
I was starting to loose my hairs

Serge
-----Original Message-----
you're passing an object, so its "pointer" is passed by value. theobject itself isn't copied, so the changes you make to the object remain.
there's a reason "reference types" are so called - they're always passedby reference.

serge calderara wrote:
Dear all,

I have really strange behviour when passing an object to a function by value:

if I create a new object of myClass from the main
application as follow:

myObj = new (ObjSource)

then the instance is creted on a separate assambly an
reach the code of the constructor of myClass
public sub new (byval obj as object)

.....
....

' here I try to channge some object value
obj.name ="test"
end sub

At this time when the object is created and I return to
the calling point in my main application , the object is also modifed in the main application, and it should be not as it is pass by value to the constructo of myClass !!

What did I miss here?

thnaks for your information
regards
Serge


.

Jul 21 '05 #3
serge calderara <an*******@discussions.microsoft.com> wrote:
Thnaks so much for your answer
I was starting to loose my hairs


For more information about this (using C# terminology, but the
principles are the same) see
http://www.pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

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

Similar topics

0
by: Mark | last post by:
Hi - I have a really strange problem - straight forward login code (on the event of a button press). Works perfectly locally - but when I upload to my host, I get the message and stack shown...
3
by: Arnold Schrijver | last post by:
I wrote a program that draws items to the screen and maintains a set of Offset values. There was a bug in the code, because objects were positioned wrongly. While debugging I found some peculiar...
3
by: serge calderara | last post by:
Dear all, I have really strange behviour when passing an object to a function by value: if I create a new object of myClass from the main application as follow: myObj = new (ObjSource)
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.