Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Main Form, Modeless Form, Forward Declaration Problem?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Legendary Pansy - 26 May 2004 00:16 GMT
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/2003/Dec/DialogTutorial.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?
Legendary Pansy - 27 May 2004 00:36 GMT
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!
Steve McLellan - 27 May 2004 01:21 GMT
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

> 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/2003/Dec/DialogTutorial.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
> ====
[quoted text clipped - 41 lines]
>
> 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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.