473,513 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Main Form, Modeless Form, Forward Declaration Problem?

Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here
http://www.c-sharpcorner.com/Code/20...logTutorial.as

Starting with "Listing 2 - Changing the constructor of the modeless dialog to accept the parent object:" line and go onwards is what I'm trying to do

Basically, there is the main form, and then there's the modeless form. I want the modeless form act like a modal form, except that the modeless form won't block the main form, which is why I dislike modal form. The problem is that modeless form won't report the dialog result, so I came to a webpage link above. Read the example, tried to do it, got stuck

I've read up about forward declaration, but that didn't help. It still kept saying that the main form's class is undefined (C2027 error from compiler). Maybe I'm doing it wrong somehow. This is how it looks like in my current project (cutting out all the uncessary clutter)

main.
===
namespace bla

#include "modelessform.h
public __gc class main : public System::Windows::Forms::For

public: void launchform(

modelessform* box = new modelessform(this)

void showsomething(modelessform* box

// get text from modelessform and put it into main's textBo
statusBar->Text = box->gettext()


modelessform.
=========
namespace bla

public __gc class main; // forward declaratio
public __gc class modelessform : public System::Windows::Forms::For

// created another constructor..
public: modelessform(main* parent

InitializeComponent()
theparentform = parent

String* gettext(){return textBox->Text;
private: main* theparentform

// somewhere very down below..
private: System::Void buttonok_Click(System::Object * sender, System::EventArgs * e

parentform->gettext(); // Compiler spits out C2027 here, saying use of undefined type 'blah::main
Close()


Given that everything compiles and runs fine, no errors/warnings, windows form pops up fine, but when trying the nifty sending parent object trick like the web page does it in C#, I get that annoying C2027. Maybe I'm missing something here or there, or have a misunderstanding that this can be done in C++ but can't. I would think a forward declaration would fix the problem, but that only fixes half the problem. Including the forward declaration of class main in class modeless form fixed the compiler error that main* wasn't define. Moving on, I then try to make theparentform pointer access its own function, and then boom, C2027 error

Help?
Nov 17 '05 #1
2 3324
Looks like I'll just move development to Visual C# to make things less complicating. Code syntax between C# and C++ are miniscule, so C#, here I come!
Nov 17 '05 #2
You've included modelessform.h inside the namespace declaration. I'm not
sure if that's causing you're problem, but it probably won't help.

Somewhere in modelessform you need to include main.h, otherwise, as the
compiler points out, parentform is of an undefined type (it's just a
declaration). If I were you, to avoid the inevitable circular include, I'd
create modelessform.cpp and stick the offending code in there.

HTH,

Steve

"Legendary Pansy" <hq***@hotmail.com> wrote in message
news:FD**********************************@microsof t.com...
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here: http://www.c-sharpcorner.com/Code/20...ogTutorial.asp

Starting with "Listing 2 - Changing the constructor of the modeless dialog to accept the parent object:" line and go onwards is what I'm trying to do.
Basically, there is the main form, and then there's the modeless form. I want the modeless form act like a modal form, except that the modeless form
won't block the main form, which is why I dislike modal form. The problem is
that modeless form won't report the dialog result, so I came to a webpage
link above. Read the example, tried to do it, got stuck.
I've read up about forward declaration, but that didn't help. It still kept saying that the main form's class is undefined (C2027 error from
compiler). Maybe I'm doing it wrong somehow. This is how it looks like in my
current project (cutting out all the uncessary clutter):
main.h
====
namespace blah
{
#include "modelessform.h"
public __gc class main : public System::Windows::Forms::Form
{
public: void launchform()
{
modelessform* box = new modelessform(this);
}
void showsomething(modelessform* box)
{
// get text from modelessform and put it into main's textBox
statusBar->Text = box->gettext();
}
}
}

modelessform.h
==========
namespace blah
{
public __gc class main; // forward declaration
public __gc class modelessform : public System::Windows::Forms::Form
{
// created another constructor...
public: modelessform(main* parent)
{
InitializeComponent();
theparentform = parent;
}
String* gettext(){return textBox->Text;}
private: main* theparentform;

// somewhere very down below...
private: System::Void buttonok_Click(System::Object * sender, System::EventArgs * e) {
parentform->gettext(); // Compiler spits out C2027 here, saying use of undefined type 'blah::main' Close();
}
}
}

Given that everything compiles and runs fine, no errors/warnings, windows form pops up fine, but when trying the nifty sending parent object trick
like the web page does it in C#, I get that annoying C2027. Maybe I'm
missing something here or there, or have a misunderstanding that this can be
done in C++ but can't. I would think a forward declaration would fix the
problem, but that only fixes half the problem. Including the forward
declaration of class main in class modeless form fixed the compiler error
that main* wasn't define. Moving on, I then try to make theparentform
pointer access its own function, and then boom, C2027 error.
Help?

Nov 17 '05 #3

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

Similar topics

2
363
by: Job Lot | last post by:
I have an in house application which uses 3 different version of the same database. When application starts a form is displayed which allows user to provide the path to the database. My problem is...
6
5191
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define...
11
2787
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
2
6020
by: Rami | last post by:
My project starts with Sub Main and then needs to display a modeless form. From some reason the application closes it self after calling the Show method. How can I avoid the application from...
8
6423
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program...
1
2248
by: Jason Richmeier | last post by:
I am experiencing some unexpected behavior with the Form Load event in a Windows application. Hopefully, someone can explain why this behavior is occurring. In my application, I have a form...
2
3042
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. · I need to display a modeless dialog from the main form. o This allows user to continue to work with the...
11
5259
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
0
1118
by: Sin Jeong-hun | last post by:
It is not hard to see such tool windows that stay always above the main form, but are modeless and are not above other applications' windows. Is this achievable with pure BCL? The only thing I know...
0
7157
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...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
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...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
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...
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.