■ After the input stream has been created, the data is read in and
placed in the TLines array pointed to by Lines. When all the data is
read in, the input stream is deleted.
■ Open then calls the SetDirty function, passing FALSE as the function
parameter The SetDirty function, and its equivalent access function.
isDirty, are the equivalent of the IsDirty flag in earlier steps of the
tutorial. A document is considered to be dirty if it contains any
changes to its data that have not been saved or committed.
■ The last thing the Open function needs to do is return. If the
document was successfully opened, Open returns TRUE.
Here’ how the code for your Open function might look:s
BOOL TDrawDocument::Open(int /*mode*/, const char far* path)
{
Lines = new TLines(5, 0, 5);
if (path)
SetDocPath(path);
if (GetDocPath()) {
TInStream* is = InStream(ofRead);
if (!is)
return FALSE;
unsigned numLines;
char fileinfo[100];
*is >> numLines;
is->getline(fileinfo, sizeof(fileinfo));
while (numLines--) {
TLine line;
*is >> line;
Lines->Add(line);
}
delete is;
}
SetDirty(FALSE);
NotifyViews(vnRevert, FALSE);
return TRUE;
}
Closing the drawing is less complicated. The Close function discards
the document’ data and cleans up. In this case, it deletes the TLiness
array referenced by the Lines data member and returns TRUE. Here’s
how the code for your Close function should look:
Chapter 2, Learning ObjectWindows
79