How do you handle references to a variable in VB.NET? Consider something
like this:
Public Class MyClass
Private m_Widget As MyWidget
End Class
I realise that if you do something like:
m_Widget = New MyWidget
The m_Widget holds a reference to the new MyWidget object. If you then do
something like:
Dim m_Reference As MyWidget = m_Widget
Then m_Reference now holds a reference to the same MyWidget object.
However, what I want is the equivilent of the C++ ** mechanism whereby
m_Reference is actually a reference to the m_Width reference if you see what
I mean :-) So that if the m_Width variable is changed to another object,
then the m_Reference also changes.
In C++ (which I'm real rusty on), I would have done something like:
Widget *m_Widget, **m_Reference;
m_Widget = New Widget;
m_Reference = &m_Widget;
Sorry if that's a real mixture - ages since I wrote a line of C++! And I
know I'm mixing pointers and references.
Thanks, Rob. 6 1058
"Rob Nicholson" <in******@community.nospam> schrieb How do you handle references to a variable in VB.NET? Consider something like this:
Public Class MyClass
Private m_Widget As MyWidget
End Class
I realise that if you do something like:
m_Widget = New MyWidget
The m_Widget holds a reference to the new MyWidget object. If you then do something like:
Dim m_Reference As MyWidget = m_Widget
Then m_Reference now holds a reference to the same MyWidget object.
However, what I want is the equivilent of the C++ ** mechanism whereby m_Reference is actually a reference to the m_Width reference if you see what I mean :-) So that if the m_Width variable is changed to another object, then the m_Reference also changes.
In C++ (which I'm real rusty on), I would have done something like:
Widget *m_Widget, **m_Reference; m_Widget = New Widget; m_Reference = &m_Widget;
Sorry if that's a real mixture - ages since I wrote a line of C++! And I know I'm mixing pointers and references.
If you need a reference to a reference, put the 2nd reference into a class
and store a reference to an instance of that class.
Armin If you need a reference to a reference, put the 2nd reference into a class and store a reference to an instance of that class.
Hmm, I thought of that using ByRef in a class method and then storing that
in a class variable:
Public Class RefClass
Private m_Reference as MyWidget
Sub StoreReference(ByRef Widget As MyWidget)
m_Reference = Widget
End Sub
But whilst this does indeed pass in a reference, what gets store in
m_Reference is the reference to the Widget object, not the reference to the
variable referencing the Widget object.
Cheers, Rob.
"Rob Nicholson" <in******@community.nospam> schrieb If you need a reference to a reference, put the 2nd reference into a class and store a reference to an instance of that class.
Hmm, I thought of that using ByRef in a class method and then storing that in a class variable:
Public Class RefClass
Private m_Reference as MyWidget
Sub StoreReference(ByRef Widget As MyWidget) m_Reference = Widget End Sub
But whilst this does indeed pass in a reference, what gets store in m_Reference is the reference to the Widget object, not the reference to the variable referencing the Widget object.
Correct.
(there's nothing I can add)
Armin
> Correct. (there's nothing I can add)
Hmm, bit of an omission that. I can code around it by in effect creating a
little class that contains the pointer and do it that way. Or was that what
you were suggesting in the first place?
Thanks, Rob.
"Rob Nicholson" <in******@community.nospam> schrieb Correct. (there's nothing I can add)
Hmm, bit of an omission that. I can code around it by in effect creating a little class that contains the pointer and do it that way. Or was that what you were suggesting in the first place?
Yes, that's what I suggested. But, I've never needed it.
Armin
Hi Rob,
In addition to Armin's comment, I hope the following information is also
helpful for you.
Based on my knowledge, there is a way which is called "RefByRef", just like:
shared sub Main
dim myObject as new SomeClass
Test(myObject)
End sub
Public sub Test(ByRef v1 as SomeClass)
//now v1 has a reference to MyObject(reference) and not to the actual Object
End sub
I hope the above information is helpful for you. Thanks and have a nice day!
Best Regards,
Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
-------------------- From: "Rob Nicholson" <in******@community.nospam> Subject: Reference to a variable Date: Thu, 16 Feb 2006 18:09:55 -0000 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.1830 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 Message-ID: <ue**************@TK2MSFTNGP14.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.vb NNTP-Posting-Host: host217-45-2-100.in-addr.btopenworld.com 217.45.2.100 Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.languages.vb:318033 X-Tomcat-NG: microsoft.public.dotnet.languages.vb
How do you handle references to a variable in VB.NET? Consider something like this:
Public Class MyClass
Private m_Widget As MyWidget
End Class
I realise that if you do something like:
m_Widget = New MyWidget
The m_Widget holds a reference to the new MyWidget object. If you then do something like:
Dim m_Reference As MyWidget = m_Widget
Then m_Reference now holds a reference to the same MyWidget object.
However, what I want is the equivilent of the C++ ** mechanism whereby m_Reference is actually a reference to the m_Width reference if you see
whatI mean :-) So that if the m_Width variable is changed to another object, then the m_Reference also changes.
In C++ (which I'm real rusty on), I would have done something like:
Widget *m_Widget, **m_Reference; m_Widget = New Widget; m_Reference = &m_Widget;
Sorry if that's a real mixture - ages since I wrote a line of C++! And I know I'm mixing pointers and references.
Thanks, Rob.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kench |
last post by:
I was curious and playing with pointers and references to see what's
different between them.
Other than the obvious ones involving C++ syntax & things like references
cannot be modified with...
|
by: Jim Red |
last post by:
hello
first of all, i know, there are no classes in javascript. but i will use
that word for better understanding of my question.
here we go. i have three classes and need a reference to the...
|
by: Dave Hammond |
last post by:
In document "A.html" I have defined a function and within the document
body have included an IFRAME element who's source is document "B.html".
In document "B.html" I am trying to call the function...
|
by: daniel |
last post by:
This is a pretty basic-level question, but I'd really like to know, so
thanks for any help or pointers you can provide (like what I would
google for ;o)
Suppose:
<code>
myFunc()
{
|
by: Jake Barnes |
last post by:
Using javascript closures to create singletons to ensure the survival
of a reference to an HTML block when removeChild() may remove the last
reference to the block and thus destory the block is...
|
by: Kuku |
last post by:
What is the difference between a reference and a pointer?
|
by: ravi |
last post by:
Hi,
i am a c++ programmer,
now i want to learn programming in c also.
so can anybody explain me the difference b/w call by reference and
call by
pointer (with example if possible).
|
by: =?Utf-8?B?QWxla3MgS2xleW4=?= |
last post by:
When I call sub in VB I can sent value of variable or reference to this
value. The question is. Suppose I have class
public class AA
....
end class
and declare object of this class
dim objAA as...
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope....
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |