20th Chapter-Development Delphi Object Type Data management function (five) (5)

Source: Internet
Author: User
Tags header

20.3.2 Database BLOB field application

Delphi VCL provides a Tblobstream object to support access to a database BLOB field. The function of Delphi's Tblobstream object lies on one hand, Delphi application can make full use of the data management ability of multimedia database. On the other hand, we can use Delphi Object Pascal's program design ability to provide the bottom control ability and the omni-directional function expansion scope to the relational multimedia database.

The use of 20.3.2.1 Tblobstream

The Tblobstream object uses a Tblobfield type object as a parameter to create a BLOB stream that is associated with a BLOB field, and then accesses the data in the Blob field with the access method of the available stream.

Var

Blobstream:tblobstream;

I:integer;

Begin

Blobstream: = Tblobstream.create (Tblobfield (cardtable.fields[10), bmwrite);

With Twriter.create (Blobstream, 4096) do

Try

For I: = 0 to Designwin.controlcount-1 do

Begin

Writeinteger (Mmid[i]);

Writerootcomponent (Designwin.controls[i]);

{Write appropriate media extension information}

......

End

Writelistend;

Finally.

Free;

End

Blobstream.free;

Cardtable.post;

End

The Fields variable is an array of fields representing database records, FIELDS[10] is the BLOB field of the database. The Cardtable post method feeds the database's modifications to the physical storage of the database.

The above program is a part of the Hypermedia card storage source program, we are to save the card in the Database BLOB field, the implementation of the hypertext and relational database two data management methods together. The procedure for reading cards is as follows:

Var

Propinfo:ppropinfo;

Method:tmethod;

Blobtream:tstream;

I:integer;

Begin

Blobstream: = Tblobstream.create (Tblobfield (cardtable.fields[10)), bmread);

With Treader.create (Blobstream, 4096) do

Try

While does Endoflist do

Begin

Case Readinteger of

Idtext:begin

Ctrl: = Tcontrol (readrootcomponent (nil));

Propinfo: = Getpropinfo (Ctrl.classinfo, ' OnClick ');

method.code:= self.methodaddress (methodname);

Method.data: = Self;

If Method.code <> Nil Then

Setmethodprop (Ctrl, Propinfo, method);

Designwin.insertcontrol (Ctrl);

End

Idimage:

......

End

......

Writelistend;

End

Finally.

Free;

End

Filestream.free;

End

20.3.2.2 blob fields and graphic images

In the multimedia database processing more is the graph image, therefore the early multimedia database when expands the relational database often is adds one image field. A BLOB field is stored in binary data so that it is fully capable of expressing graphic image data.

The Loadfrombitmap and Savetobitmap methods are provided in the Tblobfield object to access bitmap data. They are all using the Blobstream object on the implementation.

Procedure Tblobfield.loadfrombitmap (BITMAP:TBITMAP);

Var

Blobstream:tblobstream;

Header:tgraphicheader;

Begin

Blobstream: = Tblobstream.create (Self, bmwrite);

Try

if (DataType = ftgraphic) or (DataType = fttypedbinary) Then

Begin

Header.count: = 1;

Header.htype: = $0100;

Header.size: = 0;

Blobstream.write (header, SizeOf (header));

Bitmap.savetostream (Blobstream);

Header.size: = blobstream.position-sizeof (Header);

Blobstream.position: = 0;

Blobstream.write (header, SizeOf (header));

End Else

Bitmap.savetostream (Blobstream);

Finally

Blobstream.free;

End

End

Procedure Tblobfield.savetobitmap (BITMAP:TBITMAP);

Var

Blobstream:tblobstream;

Size:longint;

Header:tgraphicheader;

Begin

Blobstream: = Tblobstream.create (Self, Bmread);

Try

Size: = blobstream.size;

If Size >= SizeOf (tgraphicheader) Then

Begin

Blobstream.read (header, SizeOf (header));

if (Header.count <> 1) or (Header.htype <> $0100) or

(Header.size <> size-sizeof (Header)) Then

Blobstream.position: = 0;

End

Bitmap.loadfromstream (Blobstream);

Finally

Blobstream.free;

End

End

Program in two ways to access data, for bitmap data, the beginning of the data is the flow of the potition 0, for graphics or other types of BLOB data, the flow of position for the sizeof (Header) + 1, that is, a lot of information.

20.3.2.3 blob field and text

The Delphi blob field adds the ability to handle large text. You can freely exchange data in Tblobfield and strings.

Procedure Tblobfield.loadfromstrings (strings:tstrings);

Var

Blobstream:tblobstream;

Begin

Blobstream: = Tblobstream.create (Self, bmwrite);

Try

Strings.savetostream (Blobstream);

Finally

Blobstream.free;

End

End

Procedure Tblobfield.savetostrings (strings:tstrings);

Var

Blobstream:tblobstream;

Begin

Blobstream: = Tblobstream.create (Self, Bmread);

Try

Strings.loadfromstream (Blobstream);

Finally

Blobstream.free;

End

End

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.