Flow in Delphi

xiaoxiao2021-03-06  93

What is the flow? Flow, simply, is a tool to establish an abstract processing data on an object-oriented basis. In the stream, some basic operations of processing data are defined, such as reading data, write data, etc., programmers are convection all operations without having to care about the true flow of the other data of the stream. The flow can not only handle files, but also process dynamic memory, network data, etc. If your convection operation is very skilled, it utilizes the convenience of flow in the program, and the writing process will greatly improve efficiency.

I. Basic concept and function declaration of Delphi

In Delphi, all current objects of all current objects are TSTREAM classes, which define common attributes and methods of all streams.

The properties defined in the TSTREAM class are as follows:

1, SIZE: This property returns the data size in the stream in bytes.

2, Position: This property controls the location of the pointer in the stream.

There are four virtual methods defined in TSTream:

1, read: This method implements the data from the stream. The function is:

Function Read (var buffer; count: longint; virtual; abstentract;

The parameter buffer is a buffer placed in the data read, and count is the number of bytes of data that needs to be read. The method returns the value of the number of bytes actually read, which can be less than or equal to the value specified in COUNT.

2, WRITE: This method implements writing data to the stream. The function is:

Function Write (VAR Buffer; Count: longint; virtual; abstentract;

The parameter buffer is a buffer that will write data in the stream, and count is the length byte number of data, the method returns the number of bytes in the actual write stream.

3. SEEK: This method implements the movement of the pointer in the stream. The function is:

Function seek (offset: longint; origint; virtual; abstentract;

The parameter OFFSET is the number of offset bytes, and the parameter origint points out the actual meaning of the OFFSET, which may be as follows:

SOFROMBEGINNING: OFFSET is where the movement of the pointer is starting. At this time, the OFFSET must be greater than or equal to zero.

SOFROMCURRENT: OFFSET is the relative position of the movement pointer and the current pointer.

SofroMend: OFFSET is the position of the end of the pointer distance data. At this time, OFFSET must be less than or equal to zero. The method returns the value of the moving pointer.

4. Setsize: This method implements the size of the data. The function is:

Function setsize (newsize: longint); virtual;

In addition, several static methods are also defined in the TSTREAM class:

1. Readbuffer: The role of this method is to read data from the current location in the stream. The function is:

Procedure Readbuffer (VAR Buffer; Count: longint);

The definition of the parameter is the same as the Read above. Note: An EREADERROR exception is generated when the number of data bytes read is different from the number of bytes you need to read.

2, WriteBuffer: The role of this method is to write data in the current location. The function is:

Procedure WriteBuffer (VAR Buffer; Count: longint);

The definition of the parameters is the same as the Write above. Note: EWRITEERROR exception will be generated when the number of data bytes written is different from the number of bytes that needs to be written.

3, CopyFrom: The role of this method is to copy the data stream from other streams. The function is:

Function CopyFrom (Source: TSTREAM; Count: longint): Longint

The parameter source is the number of data bytes that provide data for the stream of data. When Count is greater than 0, CopyFrom is copied from the current location of the Source parameter. When count is equal to 0, the copyFrom sets the position attribute of the Source parameter to 0, then copy all the data of the Source; TSTREAM has other derived classes The most commonly used TFileStream class. Use the TFileStream class to access files, first create an instance. The declaration is as follows:

Constructor Create (const filename: string; mode: word);

FileName is a file name (including path), the parameter mode is the way to open the file, which includes the file's open mode and sharing mode, which may be the value and significance as follows:

Open mode:

FMCreate: Create a file with the specified file name, if the file already exists, open it.

FMOPENREAD: Open the specified file in a read-only mode

FMOpenWrite: Open the specified file with only write mode

FMOPENREADWRITE: Open the specified file in writing mode

Sharing mode:

FMSHARECOMPAT: Sharing mode is compatible with FCBS

FMShareExClusive: Do not allow other programs to open this file in any way

FMSharednywrite: Do not allow other programs to open this file in writing

FMSharednyRead: Do not allow other programs to open this file in a read mode

FMSharednynone: other programs can open this file in any way

TSTREAM has a derived TMEMORYSTREAM, and the number of times used in actual applications is very frequent. It is called memory flow, that is, establish a stream object in memory. Its basic methods and functions are the same below.

转载请注明原文地址:https://www.9cbs.com/read-122248.html

New Post(0)