Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error assigning values?!!

Error assigning values?!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionannouncement
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raner
    wrote on last edited by
    #1

    Hi A very unexpected error happened...below is the code snippet.

    CMy3027View *pView;
    CMainFrame *pMF = (CMainFrame*)AfxGetMainWnd();
    pView = (CMy3027View*)pMF->GetActiveView();

    m_numOfValues= pView->m_imageIndex;

    where m_numOfValues is declared as a class member variable(integer), m_imageIndex is a public member variable of my CView class. 1. On debugging,pView->m_imageIndex is working fine but m_numOfValues just doesnt get assigned. It even ran into exception error. 2. In a previous version of the same program, the same method of assignment had work fine. I have no idea why it's not working suddenly. 3. When i try declaring m_numOfValues locally(in the function) instead, the assignment work fine. 4.Another problem is i declared

    CMy3027View *pView;

    in my class's header file, under private.But after assigning it in a member function, the subsequent functions do not see the assigned value. Anyone has any idea wat's happening? pls help.. thks

    A J 2 Replies Last reply
    0
    • R raner

      Hi A very unexpected error happened...below is the code snippet.

      CMy3027View *pView;
      CMainFrame *pMF = (CMainFrame*)AfxGetMainWnd();
      pView = (CMy3027View*)pMF->GetActiveView();

      m_numOfValues= pView->m_imageIndex;

      where m_numOfValues is declared as a class member variable(integer), m_imageIndex is a public member variable of my CView class. 1. On debugging,pView->m_imageIndex is working fine but m_numOfValues just doesnt get assigned. It even ran into exception error. 2. In a previous version of the same program, the same method of assignment had work fine. I have no idea why it's not working suddenly. 3. When i try declaring m_numOfValues locally(in the function) instead, the assignment work fine. 4.Another problem is i declared

      CMy3027View *pView;

      in my class's header file, under private.But after assigning it in a member function, the subsequent functions do not see the assigned value. Anyone has any idea wat's happening? pls help.. thks

      A Offline
      A Offline
      AlexO
      wrote on last edited by
      #2

      In relese that assigment might be optimized, so it is not surprizing you do not see it. As for the exception the code below might show you the problem raner wrote:_

      pView = (CMy3027View*)pMF->GetActiveView();

      if(0 == pView)

      MsgBox("This is  the problem");

      _

      R 1 Reply Last reply
      0
      • R raner

        Hi A very unexpected error happened...below is the code snippet.

        CMy3027View *pView;
        CMainFrame *pMF = (CMainFrame*)AfxGetMainWnd();
        pView = (CMy3027View*)pMF->GetActiveView();

        m_numOfValues= pView->m_imageIndex;

        where m_numOfValues is declared as a class member variable(integer), m_imageIndex is a public member variable of my CView class. 1. On debugging,pView->m_imageIndex is working fine but m_numOfValues just doesnt get assigned. It even ran into exception error. 2. In a previous version of the same program, the same method of assignment had work fine. I have no idea why it's not working suddenly. 3. When i try declaring m_numOfValues locally(in the function) instead, the assignment work fine. 4.Another problem is i declared

        CMy3027View *pView;

        in my class's header file, under private.But after assigning it in a member function, the subsequent functions do not see the assigned value. Anyone has any idea wat's happening? pls help.. thks

        J Offline
        J Offline
        Joao Paulo Figueira
        wrote on last edited by
        #3

        Downcasts are always unsafe. Are you sure that the CView* returned by GetActiveView() is a CMy3027View*? If it's not, the program may bomb...

        R 1 Reply Last reply
        0
        • A AlexO

          In relese that assigment might be optimized, so it is not surprizing you do not see it. As for the exception the code below might show you the problem raner wrote:_

          pView = (CMy3027View*)pMF->GetActiveView();

          if(0 == pView)

          MsgBox("This is  the problem");

          _

          R Offline
          R Offline
          raner
          wrote on last edited by
          #4

          oh yah, i do get the "This is the problem" message box..but what does it mean?;P

          A 1 Reply Last reply
          0
          • J Joao Paulo Figueira

            Downcasts are always unsafe. Are you sure that the CView* returned by GetActiveView() is a CMy3027View*? If it's not, the program may bomb...

            R Offline
            R Offline
            raner
            wrote on last edited by
            #5

            i don't know how to see that the returned pointer is a CMy3027View*..but i've only one CView-derived class so i thought it should be?

            J 1 Reply Last reply
            0
            • R raner

              oh yah, i do get the "This is the problem" message box..but what does it mean?;P

              A Offline
              A Offline
              AlexO
              wrote on last edited by
              #6

              it means the GetActiveView() stopped worked in your program. Check carefully what it does (if you have source control check what it used to do)

              R 1 Reply Last reply
              0
              • R raner

                i don't know how to see that the returned pointer is a CMy3027View*..but i've only one CView-derived class so i thought it should be?

                J Offline
                J Offline
                Joao Paulo Figueira
                wrote on last edited by
                #7

                Try to use a dynamic_cast. If the returned value is NULL, then the pointer is not of that class.

                R 1 Reply Last reply
                0
                • A AlexO

                  it means the GetActiveView() stopped worked in your program. Check carefully what it does (if you have source control check what it used to do)

                  R Offline
                  R Offline
                  raner
                  wrote on last edited by
                  #8

                  what is source control?...i thought it simply gets the MainFrame pointer and then the active view's pointer? anyway...i don't understand how GetActiveView() can just stop working?

                  1 Reply Last reply
                  0
                  • J Joao Paulo Figueira

                    Try to use a dynamic_cast. If the returned value is NULL, then the pointer is not of that class.

                    R Offline
                    R Offline
                    raner
                    wrote on last edited by
                    #9

                    How do i use dynamic_cast?...sorry,i've heard of it but i've never tried anything like that..

                    J 1 Reply Last reply
                    0
                    • R raner

                      How do i use dynamic_cast?...sorry,i've heard of it but i've never tried anything like that..

                      J Offline
                      J Offline
                      Joao Paulo Figueira
                      wrote on last edited by
                      #10

                      Do this:

                      pView = dynamic_cast<CMy3027View*>(pMF->GetActiveView());
                      if(pView)
                      m_numOfValues= pView->m_imageIndex;

                      You might have to turn on the RTTI option in VC.

                      R 1 Reply Last reply
                      0
                      • J Joao Paulo Figueira

                        Do this:

                        pView = dynamic_cast<CMy3027View*>(pMF->GetActiveView());
                        if(pView)
                        m_numOfValues= pView->m_imageIndex;

                        You might have to turn on the RTTI option in VC.

                        R Offline
                        R Offline
                        raner
                        wrote on last edited by
                        #11

                        It ran into exception handling error while executing pView = dynamic_cast(pMF->GetActiveView()); Anyway...is there a better way to obtain member variables of a CView class then?

                        P 1 Reply Last reply
                        0
                        • R raner

                          It ran into exception handling error while executing pView = dynamic_cast(pMF->GetActiveView()); Anyway...is there a better way to obtain member variables of a CView class then?

                          P Offline
                          P Offline
                          palbano
                          wrote on last edited by
                          #12

                          good grief :mad: the code you posted is horribly wrong considering it was provided to you correctly

                          "No matter where you go, there your are..." - Buckaoo Banzi

                          -pete

                          R 1 Reply Last reply
                          0
                          • P palbano

                            good grief :mad: the code you posted is horribly wrong considering it was provided to you correctly

                            "No matter where you go, there your are..." - Buckaoo Banzi

                            -pete

                            R Offline
                            R Offline
                            raner
                            wrote on last edited by
                            #13

                            ;Poops...i mean i did run the right statement(that below) when i got an exception error. pView = dynamic_cast(pMF->GetActiveView());

                            P 1 Reply Last reply
                            0
                            • R raner

                              ;Poops...i mean i did run the right statement(that below) when i got an exception error. pView = dynamic_cast(pMF->GetActiveView());

                              P Offline
                              P Offline
                              palbano
                              wrote on last edited by
                              #14

                              oh, u missed the "display this message as-is (no HTML)" check box. sorry :-O did you turn on the RTTI build option?

                              "No matter where you go, there your are..." - Buckaoo Banzi

                              -pete

                              R 1 Reply Last reply
                              0
                              • P palbano

                                oh, u missed the "display this message as-is (no HTML)" check box. sorry :-O did you turn on the RTTI build option?

                                "No matter where you go, there your are..." - Buckaoo Banzi

                                -pete

                                R Offline
                                R Offline
                                raner
                                wrote on last edited by
                                #15

                                :-D i c i c yes i did enable it, under project->settings->c++ language...

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups