how to access C..Doc var. from any class ?
-
hi all, does anybody know a way to access to C..Doc (or C..View) variables from ANY class in a project ? I've tried : // in a constructor of another class
CMtsBaseDoc* pDocument = ((CMtsBaseView*)(AfxGetApp()->m_pMainWnd))->pDoc;
// and even this one..CMtsBaseApp* pApp = (CMtsBaseApp*)AfxGetApp(); CMtsBaseDoc* pDocument = (pApp->GetMyView())->pDoc; // using GetMyView() from one article in codeproject
but nothing ! I just cannot get the right @ for my pDocument !? 'cos pDoc and pDocument should have the same @... and i get 2 different @ any help thanx Fred -
hi all, does anybody know a way to access to C..Doc (or C..View) variables from ANY class in a project ? I've tried : // in a constructor of another class
CMtsBaseDoc* pDocument = ((CMtsBaseView*)(AfxGetApp()->m_pMainWnd))->pDoc;
// and even this one..CMtsBaseApp* pApp = (CMtsBaseApp*)AfxGetApp(); CMtsBaseDoc* pDocument = (pApp->GetMyView())->pDoc; // using GetMyView() from one article in codeproject
but nothing ! I just cannot get the right @ for my pDocument !? 'cos pDoc and pDocument should have the same @... and i get 2 different @ any help thanx Fred -
Hello, I tried using this in a DialogBar function to point back to the Document function to get some UINT values. When calling the function from the Document, it works fine. However, when calling it from the DialogBar using the pDoc pointer, the Document function cannot access any of the Document's members--even the debugger cannot "evaluate" the member variables. Both function and members are public in my case. So it appears that this pointer is not a full-feature pointer....? I'm interested both in a solution to get Document function (data) from 'remote' classes such as my DialogBar AND (academically) what is going on in this case--why doesn't it work from a nuts & bolts standpoint. Thanks! :) JennyP
-
After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks!
CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument();
JennyP -
After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks!
CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument();
JennyP -
even by doind so, i've got a descent value of pDoc but the values it holds are all set to 0 ? :confused: i keep looking....
Now that I think of it, my values were zero, but I expected them to be zero. I'll have to set my values to be some non-zero value and see what happens. If they remain zero, then it's likely pointing to a new and separate instance of CDoc that was just created.... hmmm... JennyP
-
even by doind so, i've got a descent value of pDoc but the values it holds are all set to 0 ? :confused: i keep looking....
-
I found that I have the exact same problem. I'm going to cludge around it by passing the other class's pointer to CDoc and doing it in reversed. It's worked for me before. If you find a solution, I'd be VERY interested! Thanks! JennyP
Actually, I found that my pDoc (attained as shown in previous messages above) DOES WORK. I had another problem with my pDoc->Function that returned 0s. Anyway,..... works for me.... maybe you should double check your document values? I saw the values were good in the debugger and simply was being returned incorrectly from a function. Good luck. JennyP
-
After trying the first example and it not working (see my previous post), I tried the following and it worked. I guess the first compiles, but the pointer points not to where the actual data is stored but rather an empty data structure? (Just my WAG.) It seems the "GetActiveFrame()" may be important. If someone could explain the technical reasons, I'd appreciate it. Thanks!
CTtDoc *pDoc=(CTtDoc *)((CMainFrame *)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument();
JennyP -
Actually, I found that my pDoc (attained as shown in previous messages above) DOES WORK. I had another problem with my pDoc->Function that returned 0s. Anyway,..... works for me.... maybe you should double check your document values? I saw the values were good in the debugger and simply was being returned incorrectly from a function. Good luck. JennyP
it's alright i found my mistake : a problem of where i declared the pDocument ! so now this part of code works fine, and i get access to the real values, all good.
PgGPS::PgGPS() : CPropertyPage(PgGPS::IDD) { pDocument = NULL; pDocument = (CMtsBaseDoc*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveFrame()->GetActiveDocument(); //{{AFX_DATA_INIT(PgGPS) //}}AFX_DATA_INIT }
by doing so in the constructor pDocument, accessible anywhere within the class, allows you to access to all the variables and methods in C..Doc. :cool: Fred