Sign in to follow this  
Hinz

Free intercalling of Windows Forms : 3 hrs trial, still failed

Recommended Posts

Hinz    122
Background: Visual Studio 2005, C++ environment, in Windows Forms Application Objective : To call different forms freely from each forms Scenario : Form1 calls Form2, Form2 calls Form3, Form3 calls Form4, Form4 calls Form2 again. Clarification - "call" here means make a new object of another Form class and then ShowDialog(). If the new form is closed, itself is also closed. 1 -> 2 -> 3 -> 4 -> 2 My Method : Form1 includes Form2.h, Form2 includes Form3.h, Form3 includes Form4.h, Form4 includes Form2.h again. Situation : Compilation error. In such circular calling of forms, Form4 declare an object of Form2 by : Form2^ Form2Obj And, error is: Form2 : undeclared identifier Form2 cannot be recognized! Is there something should be put into stdafx.h instead? I am really upset about this problem...my C++ project is nearly finished and suddenly there is a big problem... Any ideas are welcomed, thanks in advance!!

Share this post


Link to post
Share on other sites
jkuhlmann    122
Maybe I'm a bit off, but I believe you can fix such a dependency issue by using forward declarations. That means that you don't include Form2.h in Form4.cpp, but just declare Form2 by doing a

class Form2;

at the beginning of Form4.cpp.

Share this post


Link to post
Share on other sites
Hinz    122
Quote:
Original post by jkuhlmann
Maybe I'm a bit off, but I believe you can fix such a dependency issue by using forward declarations. That means that you don't include Form2.h in Form4.cpp, but just declare Form2 by doing a

class Form2;

at the beginning of Form4.cpp.


at the beginning of .cpp, not .h, right? I am going to try that.
BUT there is a problem: how about the very original form when the project is created - the Form1? Where is the Form1.cpp? I can't see it in the solution explorer...

Share this post


Link to post
Share on other sites
Hinz    122
Now I "google" for about dozens of websites and I am starting to find that I am getting into a problem of circular dependency of Windows Form which is prohibited by VS2005 and there is YET a solution the problem.


I am now going to make 5 forms(1 call 2, 2call 3, 3 call 4, 4 call a copy of 2)......am I going to do something stupid?

Share this post


Link to post
Share on other sites
Moomin    332
You should have include guards (#pragma once) so the headers wont be included more than once. This then means that Form4 will have no knowledge of a form2, so you put

class Form2;

in front of the class declaration in Form4.h As long as you do not access Form2 in the header file of Form4 then everything should be fine. (You can access Form2 in the Form4 implementation file - .cpp)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this