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

Source: Internet
Author: User
Tags integer ole require

20.3.2.4 blob field and stream object

Because BLOB fields are accessed through BLOB streams in Delphi, you can easily pass data between BLOB fields and stream objects. To do this, the Tblobfield object provides the Loadfromstream and Savetostream methods.

Procedure Tblobfield.loadfromstream (Stream:tstream);

Var

Blobstream:tblobstream;

Begin

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

Try

Blobstream.copyfrom (Stream, 0);

Finally

Blobstream.free;

End

End

Procedure Tblobfield.savetostream (Stream:tstream);

Var

Blobstream:tblobstream;

Begin

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

Try

Stream.copyfrom (blobstream, 0);

Finally

Blobstream.free;

End

End

20.3.3 access to data for OLE servers embedded in Olecontainer objects

Object Linking and embedding (object linking and embedding, referred to as OLE) is a set of service features that provide a powerful way to create compound documents from information from different applications.

By describing images, graphs, tables, sounds, annotations, files, and other representations as objects, it is easier to integrate applications by using it to exchange the synthesis and processing data more easily in applications provided by different software manufacturers. OLE2.0 supports intuitive editing. Users can manipulate objects directly in the document without switching to different windows, improving the operating environment. Instead of focusing on the application and operating environment, users can do all of their work by focusing on data and files that use object technology.

OLE has become a big standard for operating system functionality, and major software vendors are supporting OLE 2.0 specifications in development tools. Delphi 2.0 provides a Olecontainer object to support the development of OLE Windows applications.

Although it is possible to create a composite document from information from different applications and to fully embody tasks and document-centric thinking, it is difficult to decompose embedded data from other applications for special processing.

For example, a set of multimedia electronic document management system, the system needs database management function document editing function, Full-text search function. In the implementation of the document editing function, if you can use the powerful editing and typesetting functions such as Chinese word or WordPad, you can save the cost of developing a document edit, and embedding the doc or RTF data of Word with an OLE compound document with intuitive editing is certainly the best choice. The problem is that full-text retrieval systems require that you search for keywords directly in a document, and therefore require that document data be detached from OLE embedded data or local data in the document.

The Olecontainer part of Delphi 2.0 supports storing OLE Object data. OLE Object data consists of two parts: OLE class description information and OLE server embedded data. Generally, OLE server embedded data is stored in a server-supported data format; For example, the format of the embedded data in Chinese Word 6.0 is the format of the Word 6.0 document. Therefore, to separate the document data from the OLE embedded document is to access the second part of the data.

We analyze the program of Delphi 2.0 's Olecontainer Object access compound document, and get the method of separating data.

Let's take a look at a program that Olecontainer objects to store data:

Procedure Tolecontainer.savetostream (Stream:tstream);

Var

Datahandle:hglobal;

Buffer:pointer;

Header:tstreamheader;

R:trect;

......

Begin

......

Try

......

If Foldstreamformat Then

Begin

R: = Boundsrect;

Header.PartRect.Left: = R.left;

Header.PartRect.Top: = R.top;

Header.PartRect.Right: = R.right;

Header.PartRect.Bottom: = R.bottom;

End Else

Begin

Header.signature: = Streamsignature;

Header.drawaspect: = Fdrawaspect;

End

Header.datasize: = GlobalSize (Datahandle);

Stream.writebuffer (header, SizeOf (header));

Buffer: = GlobalLock (Datahandle);

Try

Stream.writebuffer (buffer^, header.datasize);

Finally

GlobalUnlock (Datahandle);

End

Finally

Releaseobject (Tempstorage);

Releaseobject (templockbytes);

End

End

program, the Olecontainer object performs two times to write data to the stream.

Stream.writebuffer (header, Size (header));

Stream.writebuffer (buffer^, header.datasize);

The previous statement writes the OLE class description information, and the last sentence is the embedded data that is written to the OLE server. The header is a variable of the Tstreamheader record type. The Tstreamheader record is defined as follows:

Tstreamheader = Record

Case Integer of

0: ({New Edition OLE object}

Signature:integer;

Drawaspect:integer;

Datasize:integer);

1: ({Legacy OLE Object}

Partrect:tsmallrect);

End

Therefore, when you read the OLE server embedded data, you skip the Tstreamheader record of the file header. Here's how to detach an OLE server's embedded data:

Var

Stream:tmemorystream;

Filestream:tfilestream;

Begin

Stream: = tmemorystream.create;

FileStream: = Tfilestream.create (' TEST. DOC ', fmcreate);

With OleContainer1 do

if (state <> osempty) Then

Savetostream (Stream);

Stream.seek (Sizeof (Tstreamheader), 0);

Filestream.copyfrom (Stream, stream.size-sizeof (Tstreamheader));

Stream.free;

Filestream.free;

End

OleContainer1 contains a server object that is in Chinese Word 6.0, and the separated data is stored in the disk file "TEST" in the program. DOC "on. If you want to store on a different medium, you can use the corresponding stream object, which is similar to the separated method. However, this method does not apply to all OLE server data, such as WordPad (WordPad) in the Windows 95 attachment.

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.