sharing variables/information between two forms

Posted on 2006-03-20
Medium Priority
Last Modified: 2010-04-24
Visual c++ .net express 2005
windows xp

I have two forms, inside the same application. Form1 creates Form2, so I assume it is a "child" of some sort. Anyway, I am collecting data via rs232 in the main form (form1) and would like to pass that information to form2. I was looking for some function like "GetParent" to get a handle to the original or any other way that is typical to pass information between forms. I have tried to even compile an old c++ singleton class that I have to share the information, but it doesn't mix well with managed c++ (because of the static variables?) . Anyway, is there a "proper" way to handle this ? I don't really want an MDI type solution. I would like this to all be independent forms so that non pertinent forms can just be minimized or hidden when they aren't needed, as well as the ability to see both forms. Sample code would be most helpful! I'm pretty wet behind the ears on this, as I usually just do embedded C and VHDL.

Question by:fenriss_wolff

Accepted Solution

Knut Hunstad earned 1000 total points
ID: 16241469
Since your form2 is created by form1, then form1 can store a pointer to form2 and call functions or set member variables for form2 directly. Whether form2 is a real "child" of form1 or not is something you define when you create form2. You could also send data to form2 as messages.

Author Comment

ID: 16243978
I'm so new that I didn't even know you forms were inherited, and all I needed to do was create a set function with a pointer to my data that I want to pass from Form1 . Thx!

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question