By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

Main Form, Modeless Form, Forward Declaration Problem?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.