Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't Access Application Class data members.

Posted on 1998-11-25
4
Medium Priority
?
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 200 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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 (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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