8.3.2.2 Initialize OLE package container parts
In order for the OLE package container part to contain OLE objects, the part must be initialized. Initialization is primarily an OLE class that defines a part. If you define an OLE file and an OLE project, the OLE application part will contain the OLE object when initialization is complete.
Call the INSERTOLEOBJETDLG function to pass it to the Pinitinfo property of the OLE package container part, the Objclass,objdoc of the OLE containment part, when its parameter pinitinfo gets information about the initialization of the OLE object. The Objitem property is automatically defined.
When the initialization is complete, the OLE object is hit alive. The OLE server is controlled, and the OLE object can be edited by the user through the OLE server. When a program freezes an OLE object, the OLE package container part will contain an image or a bitmap to represent the OLE object. Define the Autoactive property of the OLE package container part to reactivate the OLE object, by default, by double-clicking the OLE Package container part to click the OLE object.
The code for the initial OLE object in the routine is as follows:
Procedure Toleobjectform.initializeoleobject (Info:pointer);
Begin
Olecontainer.pinitinfo: = Info;
Releaseoleinitinfo (Info)
End
This procedure first passes the initialization pointer to the Pinitinfo property of the OLE package container part and then frees its memory space.
When the user clicks the edit in the routine | Insert menu item, the Insert Object dialog box pops up, and when you select an object type, the OLE object is activated, and the procedure has the following code:
Procedure Toleobjectform.insertobject1click (Sender:tobject);
Var
Info:pointer;
Begin
If Insertoleobjectdlg (oleframeform, 0, Info) then
Initializeoleobject (Info);
End
8.3.3 Frozen OLE objects
If the OLE object is created by an OLE 1.0 server, the object is killed in the OLE server, and the focus and control are moved to the OLE server. To freeze an object selection "File |" Created by OLE 1.0 Exit menu item.
If the OLE 2.0 server supports local activation, the OLE server will merge menus after the OLE object is activated, and the toolbar and status bar are converted. To freeze an object, simply click the mouse anywhere in the application form that is different from the OLE package container part
The key can be labeled.
Another way to freeze an object is to set the OLE package container part's Active property to a false value. In the routine, the object | Freeze menu item implements the Freeze function. The code is as follows:
Procedure Toleobjectform.deactivate1click (Sender:tobject);
Begin
Olecontainer.active: = False
End
8.3.4 Paste OLE Object
Some OLE servers allow users to copy OLE objects to the Clipboard, and if an OLE object is copied to the Clipboard, the OLE application can paste the OLE object by initializing the OLE package container part.
8.3.4.1 Paste dialog box
To paste an OLE object into an OLE package container part, to use the Paste dialog box, there is no Paste dialog box part in Delphi, but the Pastespecialdlg function displays the Paste dialog box.
The PASTESPECIALDLG function is declared as follows:
function Pastespecialdlg (form:tform; Const First:arrang; Helpconcert:thelpcontext;var Forrmat:word; var hardle:thanlle var pinitinfo:point): Boolean;
The PASTESPECIALDLG parameter is defined as follows:
The Parameter form is the form that has the Paste dialog box, and you should pass the form name that contains the OLE package container part to the form.
The parameter format is an array of registered object formats, each of which is an array member of the Boleformat type. For example, an application can register two object formats. Registers the fembedclipfmt for the embedded object and registers the FLINKCLIPFMT for the linked object.
The Boleformat statement reads as follows:
Boleformat:record
Fmtid:word;
FMTNAME:ARRAY[0..31] of Char;
FMTRESULTNAME:ARRAY[0..31] of Char;
Fmtmediun:bolemedium;
Fmislinkble:bool;
End
Fmtid is the Clipboard format ID number of the object, Fmtid can be a standard Clipboard format: Cf_text,cf_bifmap. When you use an OLE object, you need to register a new clipboard format to handle the OLE object. The Registerclipbordformat function in the Windows API registers the format.
The fmtname representation is the name of the object that defines the name of the object that appears in the list box in the Paste dialog box. In the routine, match "%s" to the Fmtname,ole server to automatically replace the "%s" parameter with the formatted name. For example, if the OLE server is a brush, "paintbrush picture Object" will replace "%s" while the program is running.
Fmtresultname, defines the name that appears in the result check box in the Paste dialog box. In the routine, the "%s" was passed to Fmtresultname. The OLE server automatically replaces the "%s" parameter with the format result name. For example, if the OLE server is a brush, the "Paintbrush picture" will replace "%s" when the program runs.
Fmtmedium is the Bolemedium type, which is the data type that Windows determines the object format. For example, OLE union
The format of the connection object is Bole_med_stream. The OLE embedded object is formatted as Bole_med_storage. The Bolemedium function calculates the type of bolemedium you want.
Fmtislinkale determines whether the object format can be linked. The fmtislinkable of the linked object is the truth value. The fmtislinkable of the embedded object is a false value.
Parameter HelpContext defines the online Help for the Paste dialog box. If the application does not have online help, the HelpContext value is zero and the Help button will not appear in the dialog box.
The Parameter form is used to define the format on the shear-glued plate, which is modified by the PASTESPECIALDLG function. Because the application does not know the format of the Clipboard when you use the Paste dialog box. Thus, the data for the Clipboard is processed using format. In the chapter routines. The PASTESPECIALDLG function modifies the format variable to fembedclipfmt or FLINKCLIPFMT, both of which are defined in the OnCreate event of the main form. If the data on the Clipboard is not an OLE object, format will be modified to other types of formatting, such as Cf_text.
Parameter landle defines the data handle on the Clipboard. Modified by the PASTESPECIALDLG function. Clipboard data is accessed with the handle parameter when the data type of the Clipboard is not an OLE object. Handle is a handle type.
The parameter pinitinfo is a pointer to the OLE object initialization structure. This pointer is also used to describe the initialization of an OLE application part. The Pastespecialdlg function modifies the pinitinfo pointer so that it points to a valid data structure. The structure includes initialization information for the selected OLE object in the Paste dialog box.
The following describes the parts in the Paste dialog box.
Inserts data from the Clipboard into the OLE application to embed the object, choosing "Paste";
Establish a connection between an OLE server resource file and an OLE application to achieve an object connection, select: "Paste line;"
To display the smell and embedded objects as icons, select "Display as Icon". If this check box is selected, changing the icon ("Chang icon") button will show that the default icon or label for the OLE object can be changed by this button.
If the data is not in the registered format, "Paste", the "Paste link" selection key will be dimmed. Users cannot paste data from the Clipboard. In the chapter routines, the data on the Clipboard can only be fembedclipfmt (embedded objects) and FLINKCLIPFMT (linked objects).
The user selects the data type in the list box. Sometimes data is interpreted as multiple types. For example, copy the text to the Clipboard in a word processor that contains the OLE server functionality. An application can paste objects in two ways, text and OLE objects. The selection that appears in the list box is determined by the OLE server.
The user selects the OK button in the Paste dialog box, PASTESPECIALDLG returns the true value, and the initialization information about the OLE application is stored in the structure pointed to by Pinitinfo.