I know I can pass a reference to a String into a Form by
overloading the Constructor.
Public Sub New(ByRef strDX As String)
MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that
memory address so that as I make changes on this form, the
referenced string is modified back on the calling form? Or
do I have implicitly set a public value or property or
call a function on the calling form from the active form
to update the value? Thanks.
Sean 12 1993
"Sean" <an*******@discussions.microsoft.com> schrieb I know I can pass a reference to a String into a Form by overloading the Constructor.
Public Sub New(ByRef strDX As String) MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that memory address so that as I make changes on this form, the referenced string is modified back on the calling form? Or do I have implicitly set a public value or property or call a function on the calling form from the active form to update the value? Thanks.
The string itself can not be modified because strings are "immutable". If
you pass a string variable to the constructor, you can store the reference
to the string in a local variable or in a field of the class. You can not
store the reference to the passed string variable, neither locally nor as a
field.
You can create a class containing a string variable and pass an instance of
the class to the constructor. The object reference can be stored. As the
caller and the Form point to the same object, modifications made to the
string field within the object are visible from both locations.
Out of interest: What are you trying to accomplish?
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Firstly, strings are immutable in VB.NET ( cannot be changed ).
Secondly, your post is gibberish to me ( I cannot understand you).
No Offence meant.
Regards - OHM
Sean wrote: I know I can pass a reference to a String into a Form by overloading the Constructor.
Public Sub New(ByRef strDX As String) MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that memory address so that as I make changes on this form, the referenced string is modified back on the calling form? Or do I have implicitly set a public value or property or call a function on the calling form from the active form to update the value? Thanks.
Sean
--
Best Regards - OHM
O_H_M{at}BTInternet{dot}com
* "Sean" <an*******@discussions.microsoft.com> scripsit: I know I can pass a reference to a String into a Form by overloading the Constructor.
Public Sub New(ByRef strDX As String) MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that memory address so that as I make changes on this form, the referenced string is modified back on the calling form? Or do I have implicitly set a public value or property or call a function on the calling form from the active form to update the value? Thanks.
Strings are immutable in .NET, you cannot change their value without
(implicitly) creating a new string.
You can pass a reference to an instance of a class "wrapping" the string
class. Quick and Dirty:
\\\
Public Class MyString
Public Value As String
End Class
///
\\\
Dim m As New MyString()
m.Value = "Foo"
Dim x As New Foo(m)
///
\\\
Public Sub New(ByVal m As MyString)
m.Value = "Bla"
End Sub
///
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Hehe, confused the VB programmer by discussing pointers
huh?
j/k -----Original Message----- Firstly, strings are immutable in VB.NET ( cannot be
changed ).Secondly, your post is gibberish to me ( I cannot
understand you). No Offence meant.
Regards - OHM
Sean wrote: I know I can pass a reference to a String into a Form by overloading the Constructor.
Public Sub New(ByRef strDX As String) MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that memory address so that as I make changes on this form,
the referenced string is modified back on the calling form?
Or do I have implicitly set a public value or property or call a function on the calling form from the active form to update the value? Thanks.
Sean
-- Best Regards - OHM
O_H_M{at}BTInternet{dot}com
.
Probably just my confusion moving from a C++ world. I just
want to make a generic form that can set a string value on
the calling form. In C++, I would just do something like:
CString csSomeString = "Some string data";
MyForm* form = New MyForm(&csSomeString);
void MyForm::MyForm(CString *pcsString)
{
pcsLocalString = pcsString;
*pcsLocalString = "New string data";
}
.....and I was trying to find a comparable way to do it in
VB. -----Original Message----- "Sean" <an*******@discussions.microsoft.com> schrieb I know I can pass a reference to a String into a Form by overloading the Constructor.
Public Sub New(ByRef strDX As String) MyBase.New()
InitializeComponent()
End Sub
Is there anyway to set a local value to point to that memory address so that as I make changes on this form,
the referenced string is modified back on the calling form?
Or do I have implicitly set a public value or property or call a function on the calling form from the active form to update the value? Thanks.
The string itself can not be modified because strings
are "immutable". Ifyou pass a string variable to the constructor, you can
store the referenceto the string in a local variable or in a field of the
class. You can notstore the reference to the passed string variable,
neither locally nor as afield.
You can create a class containing a string variable and
pass an instance ofthe class to the constructor. The object reference can be
stored. As thecaller and the Form point to the same object,
modifications made to thestring field within the object are visible from both
locations. Out of interest: What are you trying to accomplish?
-- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
.
Hi Sean,
Your messages are something confusing yes, are you talking about real memory
adresses or about virtual pointers?
Cor Hehe, confused the VB programmer by discussing pointers huh?
j/k
"Sean" <an*******@discussions.microsoft.com> schrieb Probably just my confusion moving from a C++ world. I just want to make a generic form that can set a string value on the calling form. In C++, I would just do something like:
CString csSomeString = "Some string data"; MyForm* form = New MyForm(&csSomeString);
void MyForm::MyForm(CString *pcsString) { pcsLocalString = pcsString;
*pcsLocalString = "New string data"; }
....and I was trying to find a comparable way to do it in VB.
If you want to change a property of an object you need a reference to the
object. Consequently you should pass the reference to the Form (to the
constructor). Later you can use the Form reference to change the property.
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Cor,
I was trying to figure out a way to use real memory
addresses, al la C, and wasn't sure if it is possible in
VB.NET. Basically pass in the memory address of some
string from one form calling another, and then point to
that memory address from with the child form, in a C
fashion. I could pass in a reference to the calling form,
and set it's property that way, but I wanted to keep it
more general than that, as there are many uses for the
child form. Seems like the best was from the responses
I've gotten is to just wrap the string in a class. Thanks
everybody for your input by the way.
Sean -----Original Message----- Hi Sean,
Your messages are something confusing yes, are you
talking about real memoryadresses or about virtual pointers?
Cor
Hehe, confused the VB programmer by discussing pointers huh?
j/k
.
"Sean" <an*******@discussions.microsoft.com> schrieb I was trying to figure out a way to use real memory addresses, al la C, and wasn't sure if it is possible in VB.NET. Basically pass in the memory address of some string from one form calling another, and then point to that memory address from with the child form, in a C fashion. I could pass in a reference to the calling form, and set it's property that way, but I wanted to keep it more general than that, as there are many uses for the child form. Seems like the best was from the responses I've gotten is to just wrap the string in a class. Thanks everybody for your input by the way.
You have to think in a more OO way. :-) Which object is the string (i.e. the
string reference/variable) part of?
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
* "Sean" <an*******@discussions.microsoft.com> scripsit: Probably just my confusion moving from a C++ world. I just want to make a generic form that can set a string value on the calling form. In C++, I would just do something like:
CString csSomeString = "Some string data"; MyForm* form = New MyForm(&csSomeString);
void MyForm::MyForm(CString *pcsString) { pcsLocalString = pcsString;
*pcsLocalString = "New string data"; }
....and I was trying to find a comparable way to do it in VB.
2 ways:
Use a wrapper class for 'String' and pass an instance of this class.
- or -
Pass a reference to the form directly and access the property through
this reference.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
* "Sean" <an*******@discussions.microsoft.com> scripsit: I was trying to figure out a way to use real memory addresses
That's in general not possible (there are some cases when it's needed
(p/invoke), but it's something which is not "preferred").
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
On 2003-12-31, Sean <an*******@discussions.microsoft.com> wrote: Cor,
I was trying to figure out a way to use real memory addresses, al la C, and wasn't sure if it is possible in VB.NET. Basically pass in the memory address of some string from one form calling another, and then point to that memory address from with the child form, in a C fashion. I could pass in a reference to the calling form, and set it's property that way, but I wanted to keep it more general than that, as there are many uses for the child form. Seems like the best was from the responses I've gotten is to just wrap the string in a class. Thanks everybody for your input by the way.
The other two options that make sense here are to use an interface or
use a delegate. The idea to keep the child form more general makes
a lot of sense, at least to me. Passing the calling form into the
Child form's constructor is pretty limiting, but if you have the calling
form implement a simple interface then you can have the child accept
that interface in its constructor. That way you're still setting the
string through the owner object, but the Child doesn't need to know
anything about the parent form and can be used with any object that
implements the interface.
Or you can use delegates, either have the parent pass a string-setting
delegate to the Child Form, or have the child form raise an event when
the string should change. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: maniac |
last post by:
Hey guys, I'm new here, just a simple question.
I'm learning to Program in C, and I was recommended a book called,
"Mastering C Pointers", just asking if any of you have read it,
and if it's...
|
by: TTroy |
last post by:
Hi,
I'm just wondering why people/books/experts say "the function returns a
pointer to.." or "we have to send scanf a pointer to.." instead of "the
function returns the address of.." or "we have...
|
by: Alf P. Steinbach |
last post by:
Not yet perfect, but:
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf
http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip
To access the table of...
|
by: arnuld |
last post by:
PURPOSE: see the comments.
WHAT I GOT: infinite loop
/* This program will simply create an array of pointers to integers
* and will fill it with some values while using malloc...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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...
| |