473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1096
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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 ...

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.