The CEnrollDoc Document Class

In ClassView, you can see that AppWizard created a class, CEnrollDoc, derived from CDocument. In this topic, you will examine the member functions in this class.

Suggested Reading

To view the document class

What is the role of a document in a database application? In most other applications, the document stores data and serializes it to a file on disk. Often the application reads the whole file into memory at once and writes it back to disk as a whole. In a database application, however, the data is stored in the database, and the user usually views the data as records. Such an application doesn’t need a file.

A document in a database application, then, isn’t normally used for its serialization support. So why does Enroll have a document class?

The following code, at the beginning of EnrollDoc.h, reveals that the role of the document class in Enroll is to own the recordset.

class CEnrollDoc : public CDocument
{
   ...
   // Attributes
   public:
      CSectionSet m_sectionSet;
   ...
};

The recordset object, m_sectionSet, is embedded in the document object. Therefore, the recordset object is automatically constructed when the document object is constructed, and automatically deleted when the document object is deleted.

The document class can own any number of recordset objects in this way. For example, Step 4 of Enroll adds a second form and corresponding recordset; the document embeds this second recordset.

In a sense, then, the document class is a proxy for the database. This approach isn’t strictly necessary, but if you (or AppWizard) design your database application to use the document class this way, you can better take advantage of the framework’s document/view architecture. For example, if you have multiple views (forms) simultaneously showing some of the contents of the database, you can take advantage of the CDocument::UpdateAllViews mechanism to conveniently notify all views about an update that might have been initiated in one of the views.