Accessing data

You access data within a file using either a TFileStream or TMappedFile instance. In general, TFileStream should be used for CommonPoint application system data, and TMappedFile should be used for legacy data.

TFileStream represents a named, persistent stream, while a TMappedFile represents a file mapped into memory. You construct instances of either type using a TFile instance. The TFile instance acts as a handle to a physical file. This means that for new files, you must first create a TFile instance before you can open a file stream or mapped file. For existing files, you must obtain the TFile instance from an external program by looking it up, or by iterating through a directory.

Once you extract data from a shared file, be aware that the data might no longer reflect the contents of the file, as another task or thread might have written to the file since you read the contents. You can control access and avoid this problem by locking all or part of a file. A file lock allows you to specify the other types of access you allow concurrently, such as multiple readers or one writer. Range locks allow you to protect portions of a file.

NOTE A way to manage range locks by using TFileRangeLock is planned for a future release.

A file remains open as long as the TFileStream or TMappedFile instance exists. If you allocate one of these instances on the heap, you take responsibility for destroying the instance when you have finished.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker