Cpfile Headers - Casio ClassPad 300 Programming Manual

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

for(int i=0; i<GetSize();i++)
{
Contact *s = (Contact*)GetAt(i);
s->Write(f);
}
}
All that happens here is that we write out the total number of contacts that will be stored
as an integer, then call each contact's Write() function to write the contact. Here is the
code for the Contact Class's Write() function:
// Writes a contact to a file.
// CPStrings, every CPString just writes itself.
void Contact::Write(CPWriteFile& f)
{
firstName.Write(f);
lastName.Write(f);
phone1.Write(f);
phone2.Write(f);
email.Write(f);
address.Write(f);
}
Any class that you create that you wish to save to MCS should also have its own Write()
function.

CPFile Headers

We mentioned earlier that all CPFiles of type IMU_MCS_TypeMem should have a file
header. This header identifies what application uses the file and what type of data is
contained in the file. So far we haven't dealt with headers when either reading or writing
in the AddressBook example. This is because we haven't yet discussed where the
ContactArray class's Write or Read methods are called.
Generally, the ClassPad uses a document/view approach to display data on the screen. A
document class handles reading/writing the data, and manages the data while the
application is running. A view, on the other hand, manages how this data is displayed.
In the AddressBook example you will notice that there is an AddressDocument class that
is derived from CPDocument. This is the AddressBook's document class. It contains the
array of contacts and the Read() and Write() methods to save the array.
It is these Read() and Write() methods that call the ContactArray object's Read() and
Write() functions and handles the creation of the file header.
To create a file header, we use the CPMEMFileHeader class. The constructor simply
takes in a PEGCHAR* of your application's name and the name of the data. You can
optionally supply it with a major and minor version number:
CPMEMFileHeader (const PEGCHAR *AppName, const PEGCHAR *DataName,
Since a contact is just a bunch of
PEGCHAR MajorVersion=1, PEGCHAR MinorVersion=0);
122

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents