Here, we have a list of classes. In this case, the appropriate thing to do is put the Get/Store code in the class itself. If a change must be made to the class, the Get/Store code will be at hand and no one will forget. We must still traverse the list but for each item, there is only the call to the Get or Store method in the class. Notice that we are clearing out the list before loading. Remember that the static is persistent so the list will be persistent. If we simply add data to the list with each execution of GD, the list will get very, very long. Admittedly, clearing out the list is a bit crude but it does guarantee that what is in the list is only what came from the FRM file.
Declaration:
Class FieldData
{
Public:
Int Var1;
Int Var2;
void Store(CStaticStorage &ss)
{
ss.Store(Var1);
ss.Store(Var2);
};
void Get(CStaticStorage &ss)
{
ss.Get(Var1);
ss.Get(Var2);
};
};
CList<CFieldData, CFieldData&> MyList;
PD:
FieldData FldData;
ListSize = MyList.GetSize();
ss.Store(ListSize);
pos = MyList.GetHeadPosition();
while(pos)
{
FldData = MyList.GetNext(pos);
FldData.Store(ss);
}
ss.RetrieveStream(abStatic); // move data from ss to abstatic
GD:
CStaticStorage ss(abStatic); // get data from abStatic
FieldData FldData;
MyList.RemoveAll();
ss.Get(ListSize);
for(Indx = 0; Indx < ListSize; Indx++)
{
FldData.Get(ss);
MyList.AddTail(CFieldData(FldData.Var1, FldData.Var2));
}