Eighth chapter-Object Linking and Embedding (ii) (1)

Source: Internet
Author: User

8.3.5.2 to release OLE objects in the application

When an object is released to a form, the form has a Ondragdrop event. The object is defined as the source parameter in the Tdragdropevent method, and the Tdragdropevent method is used to handle the Ondragdrop event. If source is an OLE object, it is a derived type of the Toledropnotify object. The Toledropnotify object has a Piniinfo property that corresponds to the OLE package container part Pinitinfo property. If an OLE object is freed. Pinitinfo An initialization information structure that points to an OLE object. To implement the release feature. Simply assign the Toledropnotify Pinitinfo property to the Pinitinfo property of the OLE package container part.

The following is the code that handles the Ondragdrop event:

Procedure Toleframeform.formdragdrop (Sender, Source:tobject; X

Y:integer);

Var

Newchild:toleobjectform;

Begin

If Source is toledropnotify then

Begin

Newchild: = Createchild;

With the Source as toledropnotify do

NewChild.OLEContainer.PInitInfo: = Pinitinfo

End

End

Note Do not use Releaseoleinitinfo to release the memory assigned to the Pinitinfo property. Delphi automatically frees up this block of memory.

OLE objects in the 8.3.6 file

In an OLE application, to save changes to an OLE object, you save the object data in a file. If the object is a linked data, Delphi is automatically saved in the source file. When an object is modified, the data in the file is automatically modified. If the object is embedded, the data is stored in the form of the application program. To save modifications to an embedded object, the application should save the data in a special OLE file. If you want to edit an object for a saved file, the application must mount the OLE object from the file.

The SaveToFile method of an OLE package container part saves an object:

Olecntainer1.savetofile (' C: \sales.ole ');

The LoadFromFile method of an OLE package container part loads an object from a file into an OLE package container part.

Olecontainer1.loadfromfile (' C:\SALEs.OLE ')

This chapter routines use Save and object loading to implement the running State by saving the dialog box and opening the dialog box.

In the Oleobjectform form, add the Save dialog box part and open the dialog box part. Its main properties are shown in Table 8.4:

Table 8.4 Save the properties and values of the dialog box:

━━━━━━━━━━━━━━━━━━━━━━━━

Property value

────────────────────────

Name Saveasdialog

Defaultexit OLE

FileName. Ole

Filter OLE Files (*. OLE) |*. Ole

━━━━━━━━━━━━━━━━━━━━━━━━

Table 8.5 Properties and values for opening dialog boxes

━━━━━━━━━━━━━━━━━━━━━━━━━

property to take a value

────────────────────────

Name OpenDialog

Defaultexit OLE

FileName. Ole

Filter OLE Files (*. OLE) |*. Ole

━━━━━━━━━━━━━━━━━━━━━━━━━

The user clicks the file | Save menu item to make the OLE object save. The code is as follows:

Procedure Toleobjectform.saveas1click (Sender:tobject);

Begin

If Saveasdialog.execute Then

Olecontainer.savetofile (Saveasdialog.filename)

End

The user clicks the file | Open menu item to implement the object file mount:

Procedure Toleframeform.open1click (Sender:tobject);

Var

Newchild:toleobjectform;

Begin

F Opendialog.execute Then

Begin

Newchild: = Createchild;

NewChild.OLEContainer.LoadFromFile (Opendialog.filename)

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.