8.2 Design state OLE object creation
Dephi can create OLE objects in both the design state and the run state. This section describes the creation of design-state OLE objects.
8.2.1 Tolecontainer Parts
To create an OLE object, you add an OLE package container part to the form. An application part contains a linked or embedded object. Use this part to display data edited at the OLE server. The Objclass,objdoc,objitem property of a part defines an OLE class, file, project, and so on. To define whether an OLE object is activated locally, use the Inplaceactive property. If an OLE object can be activated locally, the OLE server menu blends with the menu of the OLE application, and the value of the Groupindex property determines the menu fusion.
To 8.2.2 OLE object creation:
1. Add the OLE package container parts to the form;
2. Click the ellipsis button of the Objclass or Objdoc property in Object Inspector, and the Insert Object dialog box appears.
3. If the OLE object you want to insert is already stored in the file, select creat from file, and then define the object's file name and pathname. If it is a linked object, select the Link check box. If it is an embedded object, select Creat new and select the OLE object in the Object Type list box;
4. Select OK button;
If you are creating a new object and the OLE server is activated, you can edit the OLE object and close the OLE server when you finish editing. A typical example is to click "File" or "file|" in the server Update menu.
5. At this point the Objclass property contains the corresponding value, if the OLE object creates or inserts a
A linked object with the Objdoc property containing the OLE file.
You can also paste an OLE object when you design the state of the object, as follows:
1. Activate the server application and select the OLE package container part;
2. In the server, copy data or objects to the Clipboard;
3. Enter Delphi integrated development environment, select OLE package container parts;
4. Select the ellipsis (...) of the Objitem property in the Object Inspector form. button
5. Select the OLE object in the list;
6. Select "Paste" to create an embedded object or select "Pastelink" to create a linked object;
7. Select OK.
The OLE package container part is initialized at this time. If you paste an embedded object, the Objclass property will contain the appropriate value. If you paste a linked object, the Objclass,objdoc,objitem property is all defined. The OLE application part contains a picture representing an OLE object.
If the OLE server program supports drag-and-drop functionality for OLE objects, drag objects from the server to the application in the design state, and the application creates a linked object, as follows:
1. Activate the server, and Delphi integrated open environment to select the object to link;
2. Click the left mouse button to drag the OLE object to the design state of the form;
3. Release the OLE object by releasing the mouse key.
The form creates an OLE application and initializes it.
Development of 8.3 OLE applications
Delphi creates an OLE object in the design state and run state, and the previous section describes how to create an OLE object in design state, which describes how to create an OLE object, paste an object, drag an object, and file operations on an OLE object in a running state. The OLE.DPR we developed is an example of an OLE application
8.3.1 OLE Application Interface development
OLE.DPR has a multiple document interface, the parent form has a menu, a toolbar, a status bar, and a subform has an OLE package container part, which is described separately below.
8.3.1.1 The OLE Application menu
The menu for an OLE application is generally consistent with the main menu of other applications, and if there are OLE 2.0 objects in your application that support local activation, then menu blending is done. Check the OLE server's data to see if the server supports local activation.
The Groupindex property of the OLE application menu determines the location of the Fusion menu, which is whether the Merge menu is replaced with the main menu or inserted into the main menu of the application.
OLE server, which combines three sets of menus: Edit,view,help, with each set of menus assigned a unique group index value. Any menu group in an OLE application with an index value of 1,3,5 is replaced by a menu with the corresponding index value in the OLE server when the menu is merged. In this routine, the Edit menu item is replaced by the server's "edit" when the menu is merged. As shown in Figure 8.3. To save the menu in your application, assign an index value that is different from the 1,3,5.
Table 8.3 The merged menu
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Menu index value feature description source (when OLE is activated)
────────────────────────────────
File 0 using File and exit programs OLE application
Edit 1 Editing OLE object OLE server
Object 2 manipulating an inactive OLE object OLE application
View 3 Modifying the observation of an OLE object OLE server
Form 4 manipulating the form OLE application
Help 5 Access Server online assistance OLE server
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
8.3.1.2 Ole toolbar and status bar
When an OLE object is activated locally, the OLE server attempts to replace the OLE application with its own toolbar and status bar. If your application wants to activate locally, you should write the appropriate code in your application to have the server use the sidebar and status bar. To do this, you must:
Set toolbars and status bars
To add a status bar to an application
Create toolbars and status bars by modifying the properties of the panel part.
When an OLE object is activated locally, the panel or other alignment control is coordinated with the OLE server program. This means
OLE servers can replace any alignment controls in the OLE application form, but locking controls cannot be replaced. For example
If the panel's Align property is Altop,alleft,albottom,alingh, the control is unlocked and the OLE server can be replaced. To make the application's toolbar and status bar not replaced, set the Locked property to a truth value.
When an OLE object is activated and the OLE server displays information about it in the status bar, the Onstatuslineevent event of the OLE application part occurs, and a text character is passed from the OLE server to the event handle. The msg parameter of the Onstatuslineevent event handle accepts text characters.
The following code uses the status bar to receive information about the OLE server:
Procedure Toleobjectform.olecontainerstatuslineevent (Sender:tobject;
msg:string);
Begin
OLEFrameForm.StatusBarPanel.Caption: = MSG
End
8.3.2 Insert OLE Object
When running the state of the object link and insert also use the Insert dialog box, Delphi does not insert a dialog box part, but can call the INSERTOLEOBJECTDLG function to display the dialog box.
The 8.3.2.1 Insertoleobjectdlg function is declared as follows:
function Insertoleobjectdlg (form:tform; Helpcontext:thelpcontext;
var pinitinfo:pointer): Boolean;
Where the Parameter form is the form that has the Insert dialog box, you typically pass the form name of the OLE package container part to the form.
Parameter Helplontext defines the online Help for the Insert Object dialog box, and 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 pinitinfo is an untyped pointer to an internal data structure that contains the initialization OLE part information. Insertoleobjectdlg modifies this pointer to point to a valid data structure that contains the selected OLE object initialization information in the dialog box list. When the pointer is used, you should call the Releaseoleinitinfo procedure to release the memory occupied by the initialization information.
When the user selects the OK button to close the Insert Object dialog box, INSERTOLEOBJECTDLG returns the truth value and points the pinitinfo to the data structure that contains the initialization information for the OLE object.