Can 2 forms communicate ?

R

Reza

Hello,

I need to have 4-5 forms in my application.
The problem is that i use the Framework editor and when i create a form
there i get new .h/.cpp files.
So i can have a main form(first form created called TestForm) and many other
forms which i can access from main form but i can not access my Main Form
from the other forms
because if i include the MainForm in the other forms i think it cause a
circular
dependency and it shows me some error messages.

My code looks like this: (read the comments in code)
Note: Using only 2 forms here
---------------------------------------
==TestForm==
#include "Inquiry.h"
#include "Search.h"
namespace TestForm
{
using namespace System;
........
using namespace System::Drawing;
using namespace InquiryForm; //Other Form
using namespace SearchForm; //Other Form


public __gc class Form1 : public System::Windows::Forms::Form
{
public:

Inquiry* pInquiry ; //I can access my other form by creating a object from
thoese classes here <<<<
Form1(void)
{
InitializeComponent();
pInquiry = new Inquiry();
}
.........
---------------------------------------------

==InquiryForm==

//#include "Form1.h" //Need to include this in order to access my
TestForm or is there other ways? <<<
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

//using namespace TestForm; //Need to include this in order to access my
TestForm or is there other ways? <<<<<<

namespace InquiryForm
{
public __gc class Inquiry : public System::Windows::Forms::Form
{
public:
Form* m_pMain;
Inquiry(void)
{
InitializeComponent();
m_pMain = new Form1();
}
.......

Please give me some hints
Thanks
/Reza
 
P

Pascal Cloup

If what you need is to access your main form (that is a kind of
"supervisor" object), follow the modifications i made.

Pascal Cloup
 
R

Reza

Thanks. I solved it.
What i did wrong was that i included the MainForm.h in the second form's .h
file.
Instead if i include this in the .cpp file and use a dynamic_cast<Mainform*>
it works fine :)
Offcourde i have an Form object in my second form which i assosiate with my
Mainform in the constructor in
MainForm where i create an object for my second form!

Thanks for the help
/Reza
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top