473,890 Members | 1,411 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 "modelessfo rm.h
public __gc class main : public System::Windows ::Forms::For

public: void launchform(

modelessform* box = new modelessform(th is)

void showsomething(m odelessform* 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(ma in* parent

InitializeCompo nent()
theparentform = parent

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

// somewhere very down below..
private: System::Void buttonok_Click( System::Object * sender, System::EventAr gs * 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 misunderstandin g 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 3345
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.cp p and stick the offending code in there.

HTH,

Steve

"Legendary Pansy" <hq***@hotmail. com> wrote in message
news:FD******** *************** ***********@mic rosoft.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(th is);
}
void showsomething(m odelessform* 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(ma in* parent)
{
InitializeCompo nent();
theparentform = parent;
}
String* gettext(){retur n textBox->Text;}
private: main* theparentform;

// somewhere very down below...
private: System::Void buttonok_Click( System::Object * sender, System::EventAr gs * 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 misunderstandin g 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 I want this form to open on top of main form. At present the main form doesn’t appears until user press OK or Cancel on the form where they provide the data path. I have used Sub Main as startup object as follows Sub main() Dim frm As New...
6
5229
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 TESTDRIVER_HPP #include <ostream> namespace ns_testdriver{ using std::ostream;
11
2820
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
6034
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 being closed. By the way in VB6 there is no problem to do it. This is the code I have: Option Explicit On
8
6469
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 closes. Dim FORM1 As New Form1 Dim FORM2 As New form2 Sub main() FORM1.Show() FORM2.Show()
1
2266
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 that I would like to show multiple times throughout the life of the application. The startup code for this form can be quite lengthy so I am hiding and showning the form (versus unloading and loading it). If I show the form non-modally (using the...
2
3061
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 application. o For the sake of example, the user could launch the modeless dialog from Form A and navigate to a Form B in the main window. · When the modeless dialog is closed, I need to perform certain logic in the main form based on the form that is...
11
5310
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 / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
0
1130
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 is using TopMost property. But this makes the form stays above all other application's windows. Should I use Win32 API for this? What I want is another form that the main form, which is; 1) modeless 2) Stays always above the main form 3) But...
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9633
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4676
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 we have to send another system

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.