Casio ClassPad 300 Programming Manual page 121

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

Advertisement

f.Realize();
f.WriteInt(8);
Without the call to Realize() the amount of space needed to write the file would have
been computed, but the file would not have been written to memory. Once you call
Realize() the file is put in write mode, and all subsequent write functions actually write to
memory.
Just like when reading files, most of the time you will be interested in writing more than
just integers. With write files you will create Write() functions for classes that need to
write to MCS.
For example, let's look at how the foo class would implement Write:
class Foo
{
...
void Write(CPWriteMCSFile& f);
}
This time we'll say that foo wants to write data members count and string. Foo's Write()
function would look something like this:
void Foo::Write(CPWriteFile& f)
{
f.WriteInt(count);
//just like class CPString had a Read function, it also has
//a write function
string.write(f);
}
Just like when calling Read(), we call CPString's Write() function to write a CPString. Keep in
mind that foo's Write() function will end up getting called twice – once to compute the amount
of memory needed to write the file, and a second time to actually write it:
Foo foo = new Foo();
CPWriteMCSFile f(FILE_NAME, FOLDER_NAME);
foo.Write(f);
f.Realize();
foo.Write(f);
Let's take another look at AddressBook and see how its ContactArray and Contact
classes implement their Write functions. First, here is the Write function for
ContactArray:
void ContactArray::Write(CPWriteFile& f)
{
//first write out how many contacts are in the array
f.WriteWord(GetSize());
//loop through that many times writing each contact
121

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents