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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serializing a class different from CDoc

Status
Not open for further replies.

StefanoCarniel

Programmer
Apr 29, 2005
15
IT
Hello evreybody.
In my project I create a new document template, with the class CProfileDoc, CProfileView. CProfileView is derived from CFormView. The form has some control (combo box and text box) and a OK button. I need to serialize the data written in the controls when the user click the ok button. So

1) in the OnProfileOk function of CProfileView, I call a

PostMessage(WM_COMMAND, ID_FILE_SAVE);

2) this automatically recall the Serialize method of the
CProfileDoc class, but I want to recall the serialize
method of the CProfileView, because the data I want to
serialize are in the CProfileView class. So I override
the CProfileDoc::Serialize in this way

void CProfileDoc::Serialize(CArchive& ar)
{
CProfileView::Serialize( ar );
}

3) I override the serialize method of the CProfileView class
in this way

void CProfileView::Serialize(CArchive& ar)
{
CObject::Serialize( ar );
if (ar.IsStoring())
{
ar << m_final_time;
}
else
{
ar >> m_final_time;
}
}

4) I also use the directives DECLARE_SERIAL and IMPLEMENT_SERIAL in the declaration of CProfileView.

When I try to compile I got the error

error C2352: 'CProfileView::Serialize' : illegal call of non-static member function

Can you help me?
Thank you
 
From your doc get an instance to the view using CDocument's GetFirstViewPosition/GetNextView methods.

Then call its Serialize.

Code:
   theViewYouFound->Serialize(ar);

By the way, storing the data in the view is kind of the opposite to what the document-view pattern is all about.

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top