Delphi data stream implementation file encryption device

Source: Internet
Author: User
Tags abstract

Data flow is a typical embodiment of object-oriented thinking in object-oriented programming language, it completely replaces the function of input and output by using function, and overcomes many drawbacks of realizing input-output function with function. In a nutshell, a stream is an abstract tool for processing data based on an object-oriented approach. In a stream, you can define some basic operations for processing data, such as reading data, writing data, and so on, and the programmer is working with the convection without caring for the true flow of data from the other end of the stream. Flow not only can process files, but also can handle dynamic memory, network data and other data forms. Mastering the operation of convection in the process of the full use of the convenience of flow, not only to write process-oriented procedures in the efficiency greatly improved. This paper takes file encryption as an example to explain the concept and application of Delphi programming.

First, the basic concept of flow

In Delphi, the base class for all stream objects is the Tstream class, which defines the common properties and methods of all streams.

The properties defined in the Tstream class are described below:

(1) Size: This property returns the size of the data in the stream in bytes.

(2) Position: This property controls the location of the access pointer in the stream.

Four virtual methods defined in the Tstream class:

(1) Read: This method realizes that the data is read out of the stream.

The prototype function is:

Function Read (var buffer;count:longint): Longint;virtual;abstract;

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

(2) Write: This method implementation writes data to the stream.

The prototype function is:

Function Write (var buffer;count:lonogint): Longint;virtual;abstract;

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

(3) Seek: This method realizes the movement of the pointer in the stream. Functions are as follows: function Seek (Offset:longint;origint:word): Longint;virtual;abstract parameter Offset represents the direction and number of bytes moved origint as the datum pointer. is a positive representation of the pointer moving from the data header to the end of the data, and the negative representation pointer moving from the end of the data to the header of the data. The parameter origint the datum that the pointer moves the reference, and the possible values are as follows: a) Sofrombeginning:offset moves at the beginning of the data, at which point the offset must be greater than or equal to zero. b) Sofromcurrent:offset the current position of the pointer as the benchmark. c) The Sofromend:offset is based on the location where the data ends. Offset must be less than or equal to zero at this time. The method returns the position of the pointer after the value is moved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.