Error assigning values?!!
-
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
-
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
Downcasts are always unsafe. Are you sure that the
CView*
returned byGetActiveView()
is aCMy3027View*
? If it's not, the program may bomb... -
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");
_
-
Downcasts are always unsafe. Are you sure that the
CView*
returned byGetActiveView()
is aCMy3027View*
? If it's not, the program may bomb... -
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?
Try to use a
dynamic_cast
. If the returned value isNULL
, then the pointer is not of that class. -
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)
-
Try to use a
dynamic_cast
. If the returned value isNULL
, then the pointer is not of that class. -
How do i use dynamic_cast?...sorry,i've heard of it but i've never tried anything like that..
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.
-
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.
-
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?
-
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
-
;Poops...i mean i did run the right statement(that below) when i got an exception error. pView = dynamic_cast(pMF->GetActiveView());
-
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