473,778 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass an object by Reference to another form?

Hi,
I would like to know whether there's any way for me to pass an object by
reference to another form?

Regards
Vanessa
Jul 21 '05
11 8815


Jon Skeet wrote:
Rick <rrquick@nosp am-com> wrote:
Why have the DataSet in Form A at all? Why not have an independant class
(a singleton) that holds the DataSet and shares it across Form A and
Form B?

I don't see why a singleton is needed here at all. I would suggest
creating a new instance of the independent class, and passing a
reference to that instance to the constructors of both Form A and Form
B. Using a singleton avoids the need for that reference, but could
prove restrictive later on.


True, I did think about that but then I can't think of a reason why (in
her situation) she would want to keep an instance being passed around
for a convenient class wrapping the DataSet. Her requirement was to keep
it consistent by making any change in another form reflect back to the
other (or others). Since it's only a DataSet and not a user defined
class which could grow into something more meaningful or useful,
requiring separate instances, I believe a singleton is probably the
best, clean choice. Then again, that's only my honest opinion :)

Rick

Jul 21 '05 #11
Rick <rrquick@nosp am-com> wrote:
I don't see why a singleton is needed here at all. I would suggest
creating a new instance of the independent class, and passing a
reference to that instance to the constructors of both Form A and Form
B. Using a singleton avoids the need for that reference, but could
prove restrictive later on.
True, I did think about that but then I can't think of a reason why (in
her situation) she would want to keep an instance being passed around
for a convenient class wrapping the DataSet.


Well, there's nothing to say for sure that there couldn't be multiple
instances of forms A and B, with each pair sharing a single DataSet.
Her requirement was to keep
it consistent by making any change in another form reflect back to the
other (or others). Since it's only a DataSet and not a user defined
class which could grow into something more meaningful or useful,
requiring separate instances, I believe a singleton is probably the
best, clean choice. Then again, that's only my honest opinion :)


I tend to shy away from using Singletons unless it's a real design
decision to go for them, rather than just as a convenience.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #12

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

Similar topics

12
1801
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though, I just have two forms. One is the main window, and the other sets some preferences like names, and email addresses. When someone opens this window, and enters values on this page, I'd like it to set the values of public variables on the main...
110
9960
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 must be an object instead of
3
3890
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around the problem, I thought of using OPENARGS to pass information to the form being opened (instead of using WHERE). In the parent form, I have generated a RecordSet (RS) with the information
4
1470
by: Vaughn | last post by:
When I pass a reference to my current form, frm_x, when I create and show another form, frm_y, do I have access to all of the public methods, controls, members, etc.. of frm_x from frm_y? In my code, I pass the reference like this: private void btn_ListEmp_Click(object sender, System.EventArgs e) { frm_EmpList frm_empList = new frm_EmpList(this); frm_empList.MdiParent = this.MdiParent; frm_empList.Show();
4
3409
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then 42. They say that 42 is printed the second time since the value was wrapped in a class and therefore became passed by reference. (sorry for any typos I am a newbie here ;-)
11
7774
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
7
2579
by: Boki | last post by:
Hi All, I can't pass data to another form: in form2: private void button1_Click(object sender, EventArgs e) { Form1 form_copy = new Form1();
12
3018
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. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
12
11111
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
9628
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
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10061
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
9923
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
6722
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
5368
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...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
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 we have to send another system
2
3627
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.