1

I am trying to create a simple record storage application but for some idiotic reason C++ is refusing to let me navigate back to my default frmview.h Form, after adding the record.

This is the code that I am trying to execute:

System::Windows::Forms::DialogResult Result = MessageBox::Show(this,String::Format("Record Added for user {0}, Add another?", txtstaffname),"title", MessageBoxButtons::YesNo, MessageBoxIcon::Information);

    if(System::Windows::Forms::DialogResult::Yes == Result)
        {
            //Do something
        }
            else
                {
                    this->Close;
                    frmview::Show;
                }

When I try to execute the debugger I get the following exception:

11  IntelliSense: a pointer-to-member is not valid for a managed class  $PROJECTDIR$\frmnew.h   444 12  Application1

Now the form that I am trying to go back to is the View Records Form which is also used to go the the current Add Records (frmnew.h) Form and I have included the following headers on both Forms:

frmview.h (View Records):

#include "frmadd.h"
#include "frmedit.h"

frmadd.h (Add Records):

#include "frmview.h"

My computer system is running Windows 8.1 and I have Visual Studio 2012 installed (.NET 4.5)

If it were up to me I would use C# or VB.NET but as part of our assignment we have to use C++.

Any help would be great, thanks.

Shell
  • 6,818
  • 11
  • 39
  • 70
RopinKain
  • 23
  • 3

2 Answers2

0

I think you are having problems with double inclusion. You are including "frmadd.h" which will include "frmview.h" and so on endlessly.

If you need to save some data from second form to the first one, you can use property and navigate safely through the forms. Hope this helps.

Ps.: I think Show method needs brackets: Show().

Emi987
  • 385
  • 1
  • 12
0

Without seeing more code to ascertain the problem I have had to assume a lot, hence the multi-solution answer:

If multiple inclusion is the problem then a pre-processor directive to only define/include if not previously included should solve the problem: wrap the whole contents on your .h files in

#pragma once
#ifndef HEADERFILENAMEHERE_H
#define HEADERFILENAMEHERE_H
//.....
original header file contents here
//.....
#endif

However based on the error you have output, I think the syntax you are using is wrong: looks like you need to call

frmview->Show(this);

instead of

frmview::Show;

Another possibility is that you may need to restructure your code to be more inline with the following:

//SecondForm.cpp

#include "StdAfx.h"
#include "FirstForm.h"
#include "SecondForm.h"

System::Void CppWinform::SecondForm::button1_Click(System::Object^  sender, System::EventArgs^  e)
{
 FirstForm^ firstForm = gcnew FirstForm();
 firstForm->Show();
 this->Hide();
}

System::Void CppWinform::FirstForm::button1_Click(System::Object^  sender, System::EventArgs^  e) {
 SecondForm^ secondForm = gcnew SecondForm();
 secondForm->Show();
 this->Hide();               
}

Let me know how you get on, and if you need any more info I will be happy to help:)

GMasucci
  • 2,834
  • 22
  • 42