DocFile Classes


TDocFile_U1.pas contains 2 classes TDocFileStorage and TDocFileStream as well as support routines and constants. These classes and routines makes working with OLE structured storage considerably easier. I can't guarantee that there are no bugs etc. so use at your own risk. If you do find any bugs or have any suggestions or improvements please contact me <dart@iafrica.com>.

This unit requires Delphi 3.x

Below is a quick description of the public class members and support routines. See my DocFile viewer for an example of using these classes. See the source and my DocFile Tutorial for more info as to how the classes work.


Download

Name ZIP Size
TDocFile_U1 TDocFile_U1.zip 4kb



Support Routines

function IsADocFile( ... ) : boolean;
Returns true if sFile is a DocFile

function OpenDocFile( ... ) : TDocFileStorage;
Opens a DocFile, returns a TDocFileStorage or nil on fail

function CreateDocFile( ... ) : TDocFileStorage;
Creates a DocFile, returns a TDocFileStorage or nil on fail

function OpenCreateDocFile( ... ) : TDocFileStorage;
First tries to open the DocFile, if that fails create it

function CompressDocFile( ... ) : boolean;
Defragments a DocFile by removing unused space


TDocFileStorage

constructor Create( Storage : IStorage );
Creates the class as a wrapper for the existsing IStorage Storage

property Storage
Access to the IStorage for API calls

property sLastError
Last error that occoured

function GetStorageName : string;
Get storage's name

function GetStorageCLSID : TCLSID;
Get storage's CLSID

function GetStorageCLSID_string : string;
Get storage's as a string

function DeleteElement( ... ) : boolean;
Deletes the named element

function RenameElement( ... ) : boolean;
Renames a element

function CopyTo( ... ) : boolean;
Copies everything in the storage to another IStorage

function SetCLSID( ... ) : boolean;
Sets the storage's CLSID

function Commit( ... ) : boolean;
Saves all unsaved data disk

function MoveElementTo( ... ) : boolean;
Move an element from this storage to another

function OpenStream( ... ) : TDocFileStream;
Open an existing stream, return a TDocFileStream

function CreateStream( ... ) : TDocFileStream;
Create a stream, return a TDocFileStream

function OpenCreateStream( ... ) : TDocFileStream;
First try open a stream if that fails create the stream

function OpenStorage( ... ) : TDocFileStorage;
Open an existing storage

function CreateStorage( ... ) : TDocFileStorage;
Create a storage

function OpenCreateStorage( ... ) : TDocFileStorage;
First try open a storage if that fails create the storage

function EnumElements( ... ) : boolean;
Enum all the elements in this storage


TDocFileStream

TDocFileStream inherites from TStream, which means that you can use an IStream just as you would any other TStream based class. TOleStream provided by borland is similar but not nearly as complete.
Below is a list of the public members, not including the non-overriden inherited members from TStream.

constructor Create( const Stream : IStream );
Creates the class as a wrapper for an existing IStream

property OleStream : IStream;
Access to the IStream for API functions

property sLastError : string;
Last error that occoured

function Seek( ... ) : Longint; override;
Seeks to a given offset in the IStream (called by the position property)

function Read( ... ) : Longint; override;
Reads data from the IStream

function ReadString : string;
Reads the remaining data in the IStream as a string

function Write( ... ) : Longint; override;
Writes data to the IStream

function WriteString( ... ) : Longint;
Writes a string to the IStream

function GetStreamName : string;
Returns the Stream's name
h="95%"> function WriteString( ... ) : Longint; Writes a string to the IStream

function GetStreamName : string;
Returns the Stream's name