Re: Can't read CString after serialization
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> ha scritto nel messaggio
news:%23qhkpp1gIHA.4164@TK2MSFTNGP05.phx.gbl...
So, I think you should write a customized version (template
specialization) of SerializeElements for your particular class
CPlanetAspect,
Another approach could be to not call CArchive.Serialize. Instead, you could
do the serialization yourself, implementing a custom serialization something
like this (not tested):
void SaveToArchive( const CArray<CPlanetData> & data, CArchive & ar )
{
ASSERT( ar.IsStoring() );
// Write number of planets
int count = data.GetCount();
ar << count;
// Write each planet data to archive
for ( int i = 0; i < count; i++ )
{
data.GetAt( i ).Serialize( ar );
}
}
Similar for loading (first you read the data count, then set array size, and
load each planet data into it):
void LoadFromArchive( CArray< CPlanetData > & data, CArchive & ar )
{
ASSERT( ar.IsLoading() );
// Read number of planets
int count;
ar >> count;
// Make room in output array
data.SetSize( count );
// Read each planet data from archive
for ( int i = 0; i < count; i++ )
{
data.GetAt(i).Serialize( ar );
}
}
Giovanni