The TContext argument is used in the case where multiple references to the same object are flattened and packed together on the same stream. The TContext is basically a dynamic dictionary built during the flattening process to assign references to repeated object instances from a set of objects to be saved. If you only want to save a single instance, then the TContext can be generated automatically by the system.
If you want to save multiple instances (which might point to overlapping instances), you need to provide a TContext. The code sample below shows both single and multiple instance flattening techniques:
// Flatten a single instance.
TPersistentClassA* a = new TPersistentClassA('a', 5);
TContiguousMemoryStream aStream(new char[100], 100);
Flatten(a,aStream);
// FlattenPointer two instances with shared parts
TPersistentClassD* d = new TPersistentClassD("me", "cguy", "bguy", a);
TMemory aStream(new char[100], 100);
TContext aContext;
if (!aStream>GetContext())
aStream>SetContext(&aContext);
aStream.FlattenPointer(d);
aStream.FlattenPointer(a);
if (aStream>GetContext() == &aContext)
aStream>SetContext(NIL);