Solved

Can't Access Application Class data members.

Posted on 1998-11-25
4
167 Views
Last Modified: 2013-11-20
Hi,
I have and SDI application. I have declared few public
variables to the Application Class as well as MainFrame class.

How do I access these variables from a new class created
by me? When I used AfxMainWnd()-> or AfxGetApp()->
it gave the following errors respectively.
error C2039: 'EntityFileName' : is not a member of 'CWnd'
error C2039: 'EntityFileName' : is not a member of 'CWinApp'

I had declared 'EntityFileName' as a Cstring in the respective classes. Is it that only base class members are
accessed using those functions?

What is the solution???
Thanks.
 
0
Comment
Question by:leena_mary
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1325270
You see, ::AfxGetApp() returns a pointer to CWinApp class and not your own application class, which, let us say is called CMyApp
To get over this problem, you do the following:

CMyApp *m_pApp;
m_pApp=(CMyApp *)::AfxGetApp();
// access your variable now like m_pApp->EntityFileName
For the variable in the MainFrame class you could do something like this:
CMainFrame *m_pFrWnd=::AfxGetApp()->m_pMainWnd;
//and then m_pFrWnd->EntityFileName

Hope this will sort your problem.
Thanks and best of luck.
pagladasu


0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325271
Hi,
Just an afterthought. You can interact with all the classes in a Document-View application architecture.
The important thing is that most funtions will return a pointer to the base class. Since with a pointer to the base class, you can only access the base class members even if you make it point to a derived class object. The only way it helps is in implementing run time polymorphism. If you want this pointer to access derived class members also, you must do an exclusive type-casting.
Hope this will clear up your doubts. Any other queries, feel free to clarify them. My email address is:
espical@hotmail.com
Thanks.
pagladasu.
0
 

Author Comment

by:leena_mary
ID: 1325272
Thanks, pagladasu.

0
 

Author Comment

by:leena_mary
ID: 1325273
Thanks, pagladasu.

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 51
windows 10 how make picture as desktop background 2 65
Fibonacci challenge 11 133
Authenticate using sesu from script 7 58
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question