Programming C++Builder Working with Files, Approaches to File I/O in Delphi or C++Builder
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149

Working with Files.

BaseCLX supports several ways of working with files. In addition to using file streams, there are several runtime library routines for performing file I/O. Both file streams and the global routines for reading from and writing to files are described in Approaches to file I/O.
In addition to input/output operations, you may want to manipulate files on disk. Support for operations on the files themselves rather than their contents is described in Manipulating files.

Note: When using CLX in cross-platform applications, remember that although the Object Pascal language is not case sensitive, the Linux operating system is. When using objects and routines that work with files, be attentive to the case of file names.

Approaches to File I/O.

There are three approaches you can take when reading from and writing to files:

The recommended approach for working with files is to use file streams. File streams are object instances of the TFileStream class used to access information in disk files. File streams are a portable and high-level approach to file I/O. Because file streams make the file handle available, this approach can be combined with the next one. The Using file streams discusses TFileStream in detail.
 You can work with files using a handle-based approach. File handles are provided by the operating system when you create or open a file to work with its contents. The SysUtils unit defines a number of file-handling routines that work with files using file handles. On Windows, these are typically wrappers around Windows API functions. Because the Delphi functions use Object Pascal syntax, and occasionally provide default parameter values, they are a convenient interface to the Windows API. Furthermore, there are corresponding versions on Linux, so you can use these routines in cross-platform applications. To use a handle-based approach, you first open a file using the FileOpen function or create a new file using the FileCreate function. Once you have the handle, use handle-based routines to work with its contents (write a line, read text, and so on).

The C runtime library and standard C++ library include a number of functions and classes for working with files. These have the advantage that they can be used in applications that do not use the VCL or CLX.


Add comment


Security code
Refresh

Programming - C++Builder