20th Chapter-Development Delphi Object Type Data management function (II.) (2)

Source: Internet
Author: User
Tags memory usage resource

4. Deconstruction method Destroy

The method generates a lock on the resource and then releases the resource, and finally calls the inherited destroy method to release the Resourcestream. It is implemented as follows:

destructor Tresourcestream.destroy;

Begin

Unlockresource (HGLOBAL);

FreeResource (Hresinfo);

Inherited Destroy;

End

Reviewing the Initialize approach, we are not hard to find:

Resourcestream does not allocate additional memory to the resource, but instead directly uses the memory domain referred to by the HGLOBAL handle

Resources in Resourcestream are always in the lock state during the lifetime of the stream, so the use of resourcestream is reasonably arranged according to the Windows memory usage rules

Resourcestream is only used to access resources in applications and dynamic-link libraries.

The classes provides a internalreadcomponentres function in the cell that uses the Tresourcestream object to read the part from the Delphi application. Delphi is to place the form and part information in the Rcdata section of the module resource.

20.1.7 Tblobstream Object

The Tblobstream object is a very important object in the sense of Delphi database development platform. The Tblobstream object provides techniques for modifying data in Tblobfield, Tbytesfield, or Tvarbytesfield. Developers can read and write data in a database domain as if they were a file or stream.

An important trend of traditional database development is to develop multimedia database. At present, the well-known and popular database support the multimedia function, one of the most difficult points in the multimedia data storage is the irregular data structure and the large quantity. The major database products are using BLOB technology to solve the problem of multimedia data storage. The meaning of Delphi's Tblobstream object lies in: On one hand, Delphi application can make full use of the data management ability of multimedia database, on the other hand, it can use the powerful program design ability of Object Pascal to provide omni-directional function extension of multimedia database.

Use the Tblobstream object to store data in any format in a BLOB field in a multimedia database. Generally, many multimedia databases can only support data that is supported by images, sounds, or OLE servers. With Tblobstream, it can read and write in a BLOB field, as long as it is a data format that the program can define, without the need for other assistive tools.

Tblobstream creates a connection between a database domain and a BLOB stream using the construct method. Use the Read or write method to access and change the contents of the domain, locate in the domain with the Seek method, and delete all data from the current position in the domain by using the Truncate method.

Properties and methods of 20.1.7.1 Tblobstream

The Tblobstream object inherits directly from Tstream and does not add new attributes. It overrides the read, Write, and Seek methods, providing access to the BLOB field; it adds a truncate method to implement the delete operation in the Blob field.

1. Read method

Statement: function Read (var Buffer; Count:longint): Longint;

The Read method copies the contents of count bytes from the current position of the database domain into buffer. Buffer must also allocate at least count bytes. The Read method returns the actual number of bytes transferred, because the number of bytes transferred may be less than count, so the bounds of the selector are required.

2. Write method

Statement: function Write (const Buffer; Count:longint); Override Longint;

The Write method copies the contents of count bytes from the buffer to the current location of the database domain. The buffer must be allocated a memory space of count bytes, the function returns the actual number of bytes transferred, and the transport process is also determined by the selector boundary.

3. Seek method

Statement: function Seek (offset:longint; Origin:word): Longint;

The Seek method reset the position of the pointer in the BLOB stream. If the value of the origin is sofrombeginning, the new pointer position is offset; If the value of the origin is sofromcurrent, the new pointer position is Position+offset, and if the origin value is sofromcurrent, the new pointer position is Size+offset. function to return a new pointer position value. When origin is 0 (sofrombegin), the value of offset must be greater than or equal to zero; When the value of Origin is 2 (sofromend), the value of offset must be less than or equal to zero.

4. Truncate method

Statement: procedure Truncate;

The Truncate method undoes data from the current position in Tblobfield, Tbytesfield, or Tvarbytesfield.

5. Create method

Statement: constructor Create (Field:tblobfield; Mode:tblobstreammode);

The Create method uses the field parameter to establish a join of a blob stream to a BLOB field. The value of Mode can be bmread, Bmwrite, and Bmreadwrite.

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.