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

how to reference an object that already exists

Hello,

I am trying to reference an object that already exists,
ie, I have a dll project (dllProj) which contains a simple
form. Then I have a main app and a secondary app which
both have references to dllProj. When I start the
project, the main app starts up. I then invoke the
dllProj from the main app and pass data to a property in
dllProj (PropertyOne) which then displays in a textbox on
dllProj. I can set data to another property in dllProj
(NameProperty) and then I can read NameProperty in the
main app. Then the main app starts up a secondary app
(form). I would like to read the value of NameProperty in
dllProj from the secondary app. I tried the following in
the secondary app but got an error:

Dim frm As dllProj.dllFormClass
Private Sub Form_Load(...)
Dim s As String
s = frm.NameProperty
msgbox s
End Sub

I get the error that the object frm was not set to an
instance of dllProj.dllFormClass. In the main app I say

Dim frm New dllProj.dllFormClass
Dim s As String
s = frm.NamProperty

This works fine except it is a new instance. I would like
to access the existing content of NameProperty contained
in dllProj from the secondary app. So, in addition to
having a reference to dllProj in the secondary app I also
tried

Imports dllProjNamespace

this did not help either. Is there a way I can reference
the already existing instance of dllProj from my secondary
app? Do I need to use something like GetObject?

Thanks,
Rich
Nov 21 '05 #1
2 1529
You must pass an instance of your existing form (or object), into the
new form (or object).

One way to do this would be to overload the constructor of the second
class to take the argument. For example (watch for typos):

'Button click in Form1 creates Form2 and passes ref to Form1
Public Sub Button1_Click(...) handles button1.click
Dim frm As New Form2(Me) 'Note that I'm passing in Me
frm.ShowDialog()
End Sub
'Now in Form2, we overload the constructor:
Public Sub New(frm As Form1)
'Do something with frm here
frm.NameProperty = "whatever"
End Sub

There are other ways, but this is a simple way.

Nov 21 '05 #2
Thanks. Actually, the 2nd form is a second application.
I invoke it with System.Diagnostics.Process.Start
(shelling to it). So it is not part of the original
application, although, it IS part of the project, 3
projects in one. The original application, the dll
application, and the 2nd application. I already tried the
constructor idea, but Process.Start will only pass a
string argument and not an object. Thus, I was thinking
about some form of GetObject.

-----Original Message-----
You must pass an instance of your existing form (or object), into thenew form (or object).

One way to do this would be to overload the constructor of the secondclass to take the argument. For example (watch for typos):
'Button click in Form1 creates Form2 and passes ref to Form1Public Sub Button1_Click(...) handles button1.click
Dim frm As New Form2(Me) 'Note that I'm passing in Me
frm.ShowDialog()
End Sub
'Now in Form2, we overload the constructor:
Public Sub New(frm As Form1)
'Do something with frm here
frm.NameProperty = "whatever"
End Sub

There are other ways, but this is a simple way.

.

Nov 21 '05 #3

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

Similar topics

15
by: Andy C | last post by:
I am new to python, so please bear with me if I am making some conceptual error. Basically I want to create a graph with an adjacency list representation, but I don't want any of the adjacency...
9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
4
by: mabuHB | last post by:
Hi, I am writing a small app to check for the existence of files on remote workstations. GUI is great, but when I click to check the workstations, the following error is displayed. The point of...
8
by: Brad Pears | last post by:
I want to check to see if a particular object exists using vb.net 2005. I have a class called clsContract. When the user clicks the 'New Contract' button, I want to check to see if a clsContract...
4
by: John Sheppard | last post by:
Hello there I was wondering if anyone could help me, I am trying to pass a typed dataset to a dialoged child form by reference. I have binding sources sitting on the child form. So to refresh...
21
by: Ray Cassick | last post by:
I can't believe why I had not noticed this before and why I never asked it before... When defining a string why is it not required to use the new keyword? Like: Dim a As String = New String ...
275
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'
1
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 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.