Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Program Problem

Status
Not open for further replies.

trose178

Programmer
Nov 26, 2002
26
0
0
US
Hi I'm creating my own type of addressbook program using MFC and OBDC. In my program there are 2 view classes. PersonalView and Homeview. In my MainFrm.cpp file I have this function:

void CMainFrame::SelectView(UINT ViewID)
{
CView* pOldActiveView = GetActiveView;// Get current View
// Get pointer to new view if it exists
// if it doesn't the pointer will be null
CView* pNewActiveView = (CView*)GetDlgItem(ViewID);

// If this is 1st time around for the new view
// the new view won't exist, so it must be created
if (pNewActiveView == NULL)
{
switch(ViewID)
{
case HOME_VIEW: // Create a Home view
pNewActiveView = (CView*)new CHomeview;
break; // Ends case
default:
AfxMessageBox("Invalid View ID");
return; // Ends switch statement
};

// Switching the views
// Obtain the current view context to apply the new view
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, ViewID, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView); // Activate new view
pOldActiveView->ShowWindow(SW_HIDE); // Hide old view
pNewActiveView->ShowWindow(SW_SHOW); // Show new view
pOldActiveView->SetDlgCtrlID(m_CurrentviewID); // Set old view ID
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
m_CurrentviewID = ViewID; // Save the new view ID
RecalcLayout();
}

in that it gave me an error in case HOME_VIEW on this line:
pNewActiveView = (CView*)new CHomeview;

The error said:
syntax error : CHomeview : Identifier
After that I added the include file for CHomeview and it fixed that problem but gave me a new error:

c:\program files\microsoft visual studio\myprojects\addbookdb\homeview.cpp(17) : error C2370: 'THIS_FILE' : redefinition; different storage class
c:\program files\microsoft visual studio\myprojects\addbookdb\homeset.cpp(11) : see declaration of 'THIS_FILE'

This error I do not understand at all and was wondering what could be wrong with the program.

Please help if you know what is wrong.

Tim

Occupation: Currently Studying C++ in High School
 
>> After that I added the include file for CHomeview

If you have anything that follows this form, you are WRONG.

#include "_____.cpp"

You don't include cpp files. You should include their corresponding .h files.

A header file (with a .h suffix) should contain the class declarations and function prototypes that are implemented in the source file (usually with a .c or .cpp suffix).

If you need more clarification then I suggest that you look at some C++ book; I recommend Stroustrup's The C++ Programming Language.
 
Apart from what "apatterno" has mentioned, I'd like to point out here that please take a look at the view class's definition. You'll notice that the constructor of a view class is "protected" and you can not create an object of that by using "new" operator. The view object is created (if it is not already), by using CRuntimeClass's CreateObject() method; CRuntimeClass is obtained by using RUNTIME_CLASS macro etc...etc...etc...

I'd suggest you consult the chapter on Document/View architecture from a good MFC book.

Thanks,
Rahul
 
thanks for all your help but i have already changed CHomeview to public because it would have to be.

But thanks for your help i remember that you do need to use .h files instead of .cpp thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top