473,598 Members | 3,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Classes communicating with other classes

I need to instantiate a class (Class1) in the startup form (Form1), set
some of Class1's properties then open another form (Form2) and have it
read Class1's properties and set the remainder of Class1's properties
and finally to have Form1 examine Class1 and send changes to a database.

I've tried passing Class1 into a property of Form2 and every combination
of Friend declaration that I can think of and can't get this to work.

I'm not fluent in this class based paradigm. How can I make an
instantiated class visible to a class (Form) where it wasn't
instantiated?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
6 1049
PaulN,

You should be able to dimension a public or friend variable in the
declarations section of Form2 and assign an object from Form1 to the public
or friend variable.

You should also be able to change Form2's constructor to accept a reference
to the object from Form1.

Maybe you could post some code that you are trying.

Kerry Moorman

"PaulN" wrote:
I need to instantiate a class (Class1) in the startup form (Form1), set
some of Class1's properties then open another form (Form2) and have it
read Class1's properties and set the remainder of Class1's properties
and finally to have Form1 examine Class1 and send changes to a database.

I've tried passing Class1 into a property of Form2 and every combination
of Friend declaration that I can think of and can't get this to work.

I'm not fluent in this class based paradigm. How can I make an
instantiated class visible to a class (Form) where it wasn't
instantiated?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #2
When you say you can't get it to work...What error are you getting? What
are the results?

"PaulN" <pa***@adhe.ark net.nospam.edu> wrote in message
news:pa***@adhe .arknet.nospam. edu:
I need to instantiate a class (Class1) in the startup form (Form1), set
some of Class1's properties then open another form (Form2) and have it
read Class1's properties and set the remainder of Class1's properties
and finally to have Form1 examine Class1 and send changes to a database.

I've tried passing Class1 into a property of Form2 and every combination
of Friend declaration that I can think of and can't get this to work.

I'm not fluent in this class based paradigm. How can I make an
instantiated class visible to a class (Form) where it wasn't
instantiated?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 21 '05 #3
I created a do nothing solution to get rid of everything that doesn't
have to do with the problem I'm having.

'************** *************** *************** *************** ************
*****
Public Class Form1
Inherits System.Windows. Forms.Form
Dim cls As Class1
Public Sub New()
MyBase.New()
InitializeCompo nent() 'this form contains only Button1 and
Lable1
cls = New Class1
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
Dim frm As New Form2
frm.ShowDialog( )
Label1.Text = cls.Test
End Sub
End Class
'************** *************** *************** *************** ************
*****
Public Class Form2
Inherits System.Windows. Forms.Form
Friend cls As Class1
Public Sub New()
MyBase.New()
InitializeCompo nent() 'this form contains no controls
cls.Test = "string" 'ERROR OCCURS HERE
End Sub
End Class
'************** *************** *************** *************** ************
*****
Public Class Class1
Private myTest As String
Public Sub New()
MyBase.new()
End Sub
Public Property Test() As String
Get
Return myTest
End Get
Set(ByVal Value As String)
myTest = Value
End Set
End Property
End Class

When I run this I get this error:
An unhandled exception of type 'System.NullRef erenceException '
occurred in WindowsApplicat ion1.exe
Additional information: Object reference not set to an instance of
an object.

In the assignment operation of Form2.New

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4
PaulN,

On Form1, in Button1' click event you need:

Dim frm As New Form2
frm.cls = cls '<------- add this line
frm.ShowDialog( )
Label1.Text = cls.Test

Kerry Moorman

"PaulN" wrote:
I created a do nothing solution to get rid of everything that doesn't
have to do with the problem I'm having.

'************** *************** *************** *************** ************
*****
Public Class Form1
Inherits System.Windows. Forms.Form
Dim cls As Class1
Public Sub New()
MyBase.New()
InitializeCompo nent() 'this form contains only Button1 and
Lable1
cls = New Class1
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
Dim frm As New Form2
frm.ShowDialog( )
Label1.Text = cls.Test
End Sub
End Class
'************** *************** *************** *************** ************
*****
Public Class Form2
Inherits System.Windows. Forms.Form
Friend cls As Class1
Public Sub New()
MyBase.New()
InitializeCompo nent() 'this form contains no controls
cls.Test = "string" 'ERROR OCCURS HERE
End Sub
End Class
'************** *************** *************** *************** ************
*****
Public Class Class1
Private myTest As String
Public Sub New()
MyBase.new()
End Sub
Public Property Test() As String
Get
Return myTest
End Get
Set(ByVal Value As String)
myTest = Value
End Set
End Property
End Class

When I run this I get this error:
An unhandled exception of type 'System.NullRef erenceException '
occurred in WindowsApplicat ion1.exe
Additional information: Object reference not set to an instance of
an object.

In the assignment operation of Form2.New

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5
Yeah, that's the ticket!!! Thanks. It's getting close.

Now, what event fires in Form2 when I call it's .ShowDialog() from
Form1? That's where I need to be filling in the blanks of the real
form2.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
PaulN,

You can probably use Form2's Form_Load event.

Kerry Moorman

"PaulN" wrote:
Yeah, that's the ticket!!! Thanks. It's getting close.

Now, what event fires in Form2 when I call it's .ShowDialog() from
Form1? That's where I need to be filling in the blanks of the real
form2.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #7

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

Similar topics

6
1597
by: Piotr Getka | last post by:
Hi I have 3 classes: - CMainFrame - CPitApp - CPitView In class CPitApp i create object CMainFrame* pMainFrame = new CMainFrame and in class CMainFrame there is:
1
1557
by: ptkacz | last post by:
I've got two classes, B and C, each performing essentially the same functionality, except for the fact that they each operate on a different data type, and that they each have a class method that has different logic to work with the respective datatype. I was thinking that I'd create an abstract template class A, that would be inhereted by both B and C classes. All that would be left to do then, is implement a single method in B and C,...
3
23859
by: Stan | last post by:
Hallo, I have developed an application in MS Access 2000 (Polish version) under MS Windows XP prof (also Polish). Now I would like to run this code on MS Windows XP EN and MS Access XP EN. I have converted the mdb to version 2002 under MS Access XP Polish and under this version everything works OK. The problem starts when I copy the mdb file to Windows XP EN and start it with MS Access XP EN. I get following error: "The expression On...
0
1807
by: DD | last post by:
I am trying to place a Word document into a form. I get the following error A problem occured while Microsoft Access was Communicating with the OLE or Activex Control the name of the ole is OLEUnbound5 class Word.Document.8 I can embedd all other windows applications and i am running OfficeXP Developer The reason i want the word doc is i have hyperlinks that run to bookmarks on the page.. as i can not work out how to do this in a
2
1430
by: Matthew Playne | last post by:
Hi, I am having a problem communicating between to classes. I have an MDI application. The parent window contains a mainMenu and a toolbar and toolbuttons, and the child form contains a richTextBox. What I am trying to do is to when a the selected text in the richTextBox is bullet indented, a menu option on the parent window is toggled on or off depending on what is
1
1027
by: TGF | last post by:
Hello, I have a little dilemma (At least it is to me). I have two classes, Class A and class B, where Class A contains the UI thread and class B contains another thread. I want to be able to communicate from ClassA to ClassB and then from ClassB to ClassA. The problem comes in with the include files. It seems there is some sort of overlapping where one is not defined when it is supposed to be. This is expected and I cannot seem to...
10
1335
by: Gabe Moothart | last post by:
Hi, I have 3 applications (2 services and a winforms app) that need to be able to send/recieve messages from each other. What is the best way to do this in .NET? I looked briefly at remoting, but it seems like it might be overkill since the applications are all on the same machine. I could use an xml file which they can all read/write to... but I was wondering what best practice for this kind of thing is in .NET. Any ideas? TIA, Gabe
6
4480
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler systems over the years. I have developed code in more than 30 distinct programming languages for a wide cariety of industries. But this issue of structures in C# is beginning to annoy me. I should also make it clear that I am not a big supporter...
6
2930
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by calling Mesh class functions. Let's say they point to each other like this: class Vertex { HalfEdge *edge; }; class HalfEdge { Vertex* vert;
26
2521
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
0
7987
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8050
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6718
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5850
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.