Transfer Variables between Windos Forms

Hello all

I am new to windows From concert and I am having one problem with my application.

I am creating a rather complex GUI via windows form and I want to be able to interact between 4 windows forms.
What I mean is that I have a parent windows from called "Form1". From that "Form1" I am calling 3 different windows froms called GPIB_setup, Serial and Parallel.
In these indivudual forms I want to input some values or choose something in radio boxes then transfer these values back to Form1 because I need them there.

I am doing this in C++/CLI, I know it is not recommended. I have read about the need to create an instance of the form and the declaring of public variables. I have writen some sample programs that transfer variables from one form to another but I have not been able to do this kind of interaction I want for my application.

I tried to include the Form1.h file into each of GPIB_setup.h, Serial.h and Paralle.h but I am getting countless errors when I do that. It is like as if the compiler does not recognize anything.
After that I have created an intermediate form where I try to "pass" the variables from these 3 forms and from that intermidiate file I try to "pass" the desired variables back to Form1.h .
This is also not working. I get the following error when I try this (code is from Form1.h)
1
2
3
4
5
6
7
8
  #include <GPIB_setup.h>
// A lot of code in between......
private: System::Void GPIBMenuItem_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
			     GPIB_setup ^ frm = gcnew GPIB_setup();
				 frm->Show();

		 }


and the error is :
error C2065: 'GPIB_setup': nichtdeklarierter Bezeichner

This error should not happen as this part of code was working before I try this kind of interaction I am talking about in this post.
I do not know if this has already been answered here. If yes please let me know where because I did a small research for it and did not find anything.

Thaks in Advance
I tried to include the Form1.h file into each of GPIB_setup.h, Serial.h and Paralle.h but I am getting countless errors when I do that.
Yes it's easy this way to get problems with circular references, anyway the child forms don't need to know the main form.
Your code looks ok. I guess the problem is in GPIB_setup.h. Does it have the same namespace?
Can you post it or even better post the complete project on Dropbox ?
Yes it does have the same namespace. They all have.
I tried to commend that line and commend any other error that came after and it seems that the problem was when I was using #include <Form1.h> in the Intermediate_Form.h , which is another Form I created to try to "circulate" my variables. So in other words there is no use for this Intermediate Form and I have absolutely no idea of how to make that interaction. I commented that line in that header file..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
//#include "Form1.h"

namespace Tester_Simulator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Zusammenfassung für Intermediate_Form
	/// </summary>
	public ref class Intermediate_Form : public System::Windows::Forms::Form
	{
	public:
		String ^ Handler_adress;
	public:
		Intermediate_Form(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}
		Intermediate_Form(String ^ txt_GPIB)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
			Handler_adress = txt_GPIB;
		}


I am using this line to "pass the information on another form( this example is back to the Form1 through the Intermediate_form(which I also had to commend it because it was produsing an error without the " #include<Form1.h>"..
1
2
3
4
5
private: System::Void Intermediate_Form_Load(System::Object^  sender, System::EventArgs^  e) 
			 {
				/* textBox1->Text = Handler_adress;
 				 Form1 ^ frm1 =gcnew Form1( textBox1->Text);*/
			 }


I have succesfully used the same method in a sample program I made following an online tutorial and it worked that is why I tried this one here.


I have just implement a basic GUI in my code and not the actual code I want to write (that is really big). I know what I have to write but there is no point in writing it since I cannot make this conenction yet.
Adittionaly, I have not written anything on the "child" forms .cpp file. Must I do the initialization of these forms from those files (similar to the way it is done in the main form .cpp file ?)?


anyway the child forms don't need to know the main form.

Can you please tell me how can I pass the arguements without creating an instance of the form and passing it through that intsance (because from what I have understood sofar is tht in order to create that instance you need to include the header file other wise you will get an undeclared identifier error)



You can see the main form as a kind of controller and the child forms use functions or properties to accept data and pass it back so they don't need to know anything about the code that calls them.
So in the main form you only need to include the header files of the child forms. Also it is normal practice to keep all the code of the child forms in the .h file. You don't need the .cpp files.

Here is a simple example how to use a child form to collect user input and pass it back to the main form. Maybe you can adapt it to your needs.

https://www.dropbox.com/sh/j1w11f1f1a2o8t2/AADGNjh8zs1BG_EIUvq59jAta?dl=0
Topic archived. No new replies allowed.