OWLNext 7.0
Borland's Object Windows Library for the modern age
|
When the user pastes or drops an OLE object into a container, the object becomes data in the container's document.
The container must store and load the object along with the rest of the document whenever the user chooses Save or Open from the File menu. The new Commit and Open methods of TOleDocument perform this chore for you. All you have to do is add calls to the base class in your own implementation of Open and Commit. The code that reads and writes your document's native data remains unchanged.
Because TOleDocument is derived from TStorageDocument rather than TFileDocument, it always creates compound files. Compound files are a feature of OLE 2 used to organize the contents of a disk file into separate compartments . You can ask to read or write from any compartment in the file without worrying about where on the disk the compartment begins or ends. OLE calls the compartments storages. The storages in a file can be ordered hierarchically, just like directories and subdirectories. Any storage compartment can contain other sub-storages.
Compound files are good for storing compound documents. When you call Open or Commit, ObjectComponents automatically creates storages in your file to hold whatever objects the document contains. All the document's native data is saved in the file's root storage. Your existing file data structure remains intact, isolated in a separate compartment. The following code shows how load compound documents. // document class declaration derived from TOleDocument class _DOCVIEWCLASS TMyDocument : public TOleDocument { // declarations }
// document class implementation
The TOleDocument::Open command does not actually copy the data for all the objects into memory. ObjectComponents is smart enough to load the data for particular objects only when the user activates them. The next code shows how to save compound documents.
By default, TOleDocument opens compound files in transacted mode. Transacted mode saves changes in a temporary buffer and merges them with the file only after an explicit command. A revert command discards any uncommitted changes. Commit buffers a new transaction. CommitTransactedStorage merges all pending transactions.
The opposite of transacted mode is direct mode. Direct mode eliminates buffers and makes each change take effect immediately. To alter the default mode, override TOleDocument::PreOpen. Omit the ofTransacted flag to specify direct mode.