📄 subject_20713.htm
字号:
<p>
序号:20713 发表者:chan 发表日期:2002-11-08 20:31:40
<br>主题:关于CList模板类的serialize问题?
<br>内容:各位大虾,你们好,我的程序出了点小问题,请帮我看看:<BR>/////////h<BR>class PlayList:public CObject<BR>{<BR>public:<BR> DECLARE_SERIAL(PlayList)<BR> PlayList();<BR> PlayList(const PlayList& pl);<BR> PlayList& operator=(const PlayList& pl);<BR> CString ListName; //播放列表项目名称<BR> CString TextName; <BR> CString GifName;<BR> CString AudioName;<BR> virtual void Serialize(CArchive& ar);<BR>};<BR><BR>///////////ccp<BR>IMPLEMENT_SERIAL(PlayList,CObject,0)<BR>PlayList::PlayList()<BR>{<BR>}<BR>PlayList::PlayList(const PlayList& pl)<BR>{<BR> this->AudioName=pl.AudioName;<BR> this->GifName=pl.GifName;<BR> this->ListName=pl.ListName;<BR> this->TextName=pl.TextName;<BR>}<BR>PlayList& PlayList::operator=(const PlayList& pl)<BR>{<BR> AudioName=pl.AudioName;<BR> GifName=pl.GifName;<BR> ListName=pl.ListName;<BR> TextName=pl.TextName;<BR> return *this;<BR>}<BR>void PlayList::Serialize(CArchive& ar)<BR>{ <BR> TRACE("PlayList::Serialize");<BR> if (ar.IsStoring())<BR> { // storing code<BR> ar<<ListName<<TextName<<GifName<<AudioName;<BR> }<BR> else<BR> { // loading code<BR> ar>>ListName>>TextName>>GifName>>AudioName;<BR> }<BR>}<BR>PlayList类的所有东西都列出来的<BR>现在我定义一个全局变量CList<PlayList,PlayList&> g_playList;<BR>在一个TransparentWnd类的构造函数里想把play.lis文件的内容读出来(现在他是空的)<BR>TransparentWnd::TransparentWnd()<BR>{ char* pszFileName ="play.lis";<BR> CFile myFile;<BR> CFileException fileException;<BR> if ( !myFile.Open(pszFileName, CFile::modeCreate | <BR> CFile::modeReadWrite,&fileException ) )<BR> { TRACE( "Can't open file %s, error = %u\n",<BR> pszFileName, fileException.m_cause );<BR> }<BR> //从play.lis文件读出播放列表到g_playList存放;<BR> CArchive archive(&myFile, CArchive::load|CArchive::bNoFlushOnDelete);<BR> g_playList.Serialize(archive);<BR> archive.Close();<BR> myFile.Close();<BR>}<BR>不知道为什么,每一次执行到g_playList.Serialize(archive);会出现一个runtime error<BR>我调试一下,可以看到执行到<BR>template<class TYPE, class ARG_TYPE><BR>void CList<TYPE, ARG_TYPE>::Serialize(CArchive& ar)<BR>{<BR>。。。。。。。。。。。。。。<BR>DWORD nNewCount = ar.ReadCount(); //在这里出错?<BR>}<BR>请大虾多多指点 cjq@tclrf.com
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:redleaf 回复日期:2002-11-10 10:24:03
<br>内容:首先说明一下,我也是才鸟一个,我在这里把我的想法说一下,你可以试一下<BR>在PlayList的定义中加入DECLARE_DYNAMIC(PlayList)宏<BR>然后在实现文件的开始部分加入IMPLEMENT_DYNAMIC(PlayList, CObject)宏
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:草席 回复日期:2002-11-10 10:43:01
<br>内容:建议先测试PlayList类的Serialize功能,然后在测试CList的Serialize功能<BR><BR>我觉得是没有正确使用CList类造成的<BR><BR>楼上的朋友说的好像没什么道理!这个宏与串行化操作没有关系
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:chan 回复日期:2002-11-11 08:41:23
<br>内容:谢谢各位,我已搞定,爽
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -