【发布时间】:2016-02-14 21:46:39
【问题描述】:
当我尝试序列化 CTypedPtrList 然后从文件中检索该列表时,会保存列表中的对象数,但不会保存对象中的实际数据。
例如,如果我要保存到文件然后从文件加载,我可以循环浏览所有四个条目,但没有一个变量会包含它们的数据。
这是适用的代码。
LEDFrame.h:
#pragma once
#include "afx.h"
#define NUMLAYERS 12
#define NUMROWS 8
#define NUMCOLUMNS 12
class LEDFrame :
public CObject
{
DECLARE_SERIAL(LEDFrame) // DECLARE_SERIAL macro call to enable serialization of CObjects
public:
bool data[NUMLAYERS][NUMROWS][NUMCOLUMNS]; // this holds one frame of the animation
int m_FrameOnTime; // this holds how long the frame is on for, a value of 1 is 10 ms
LEDFrame();
~LEDFrame();
};
typedef CTypedPtrList<CObList, LEDFrame*> CLEDFrameList; // this is the list of frames, CTypedPtrlList can be shared between document and view
LEDFrame.cpp
#include "stdafx.h"
#include "LEDFrame.h"
IMPLEMENT_SERIAL(LEDFrame, CObject, 0) // implement_serial macro call for serialization
LEDFrame::LEDFrame()
{
}
LEDFrame::~LEDFrame()
{
}
LEDCubeDoc.h
public:
virtual void Serialize(CArchive& ar);
private:
CLEDFrameList myLEDFrameList;
LEDCubeDoc.cpp
void CLEDCubeDoc::Serialize(CArchive& ar)
{
TRACE("Entering CLEDCubeDoc::Serialize");
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
myLEDFrameList.Serialize(ar);
}
LEDCubeView.h
public:
CLEDFrameList* myViewLEDFrameList; // a pointer to the documents myLEDFrameList, this edits myLEDFrameList in the doc
我认为它可能无法将列表正确保存到磁盘。这是因为当我查看保存的文件时,它只有 22 个字节。
我在 stdafx.h 中包含“afxtempl”。
我的程序基于 www.tenouk.com 上的 MFC 教程的模块 10 和 11。网址是http://www.tenouk.com/cplusplusnmfc.html
您能帮我纠正这个问题,以便我可以序列化我的 CTypedPtrList 吗?
谢谢,
安德鲁
【问题讨论】:
标签: c++ mfc visual-studio-2015