OLE Structured Storage (or Compound Documents or DocFiles … the names change regularly!) provide a clever way to have a whole file-system within a single file with nested ‘directories’ (storages) and ‘files’ (streams). There’s also the ability to do transaction processing: keeping modifications in limbo until ‘committed’ or rolled-back. The only catch has been that the necessary APIs are complex, most un-Delphi-like, and in places self-contradictory. Indeed, the DCU supplied with Delphi 1 is error-ridden. There’s also the matter of the small print and the arcane error codes! With these complexities it’s no wonder that most Delphi developers have avoided Compound Documents.
The CompDocs components available here encapsulate OLE structured storage in a straightforward and Delphi-like way. They protect you from most of the hidden problems with using the API directly and work with all versions of Delphi. As usual these components are available for free. Caveat! It is some years since these components were developed and they probably won’t function beyond D5 without a lot of tweaking. They are–regrettably–also unsupported. Nevertheless I hope you find them useful in some way.
TRootStorage models a physical file on disk while TStorage and TStorageStream model substorages and streams. Storages can be nested and can be opened in transacted mode. Creating temporary storages and streams is made easy. The TStorageStream is fully compatible with other Delphi stream types.
I have provided a simple example program, Viewer, which browses the contents of a compound file, showing the names of storages and streams. You’ll be surprised to discover the complexity of many files.