OLE Terminology VB Help

At this point.we would normally look at a few examples that demonstrate the items discussed so far, but before doing so, we must look at some OLE terms that we’ll be using in this chapter. OLE has its own terminology. You may not quite understand all the terms presented next, but they will be used later with examples.

OLE Object

An OLE,object is an item that is exposed, or made available, by an OLE server application. OLE server applications expose different types (or Classes) of objects. OLE objects are used in container applications (see the next section). illustrates, Excel (the OLE server) can expose a worksheet (the OLE object) that can be inserted as is in a Word document (the container application).

Server Application

This is the application that exposes the objects your Visual Basic application contacts. When your application must edit a document created by a server application, it contacts the server application that will be used to edit the document.

Container Application

This is an application that contains the OLE objects. Objects can be linked or embedded (more on this next). A container itself is also an object.A good example of this in Visual Basic is the Form (FRM) object, which contains controls. The container is also referred to as a client because it uses the services of OLE servers to obtain the objects.

Object Embedding

With this technique, you can insert an object from one application (the server application) into another application (the container application). The inserted object is a . copy of the original and can be manipulated and stored separately and apart from the original object. For example, you can embed a range of cells from an Excel worksheet in a Word document. To edit the cells, you switch to Excel by double-clicking the embedded cell object. If the container application supports in-place editing, you’ll see the menus of the server application right in the container application.

Object Linking

This technique is.similar to embedding, except that the embedded data are also linked to the document from which they come. Changes to the object in the server application are reflected automatically in the container application. Linking doesn’t store the object, it makes a reference to the object exposed by the server application. Each time you open the document that contains the linked object, the container application contacts the server application, which actually opens the most up-to-date version of the linked object. Linked objects are not copies. They are the originals, viewed from within different containers.

In-Place Editing

In-place editing is also known as in place activation. The functionality of the server application is incorporated into the container application, why ? enabling you to edit the object using the menus and tools of the server application. For example, if a Word document contains a range of cells from an Excel spreadsheet, double clicking the Excel object replaces the Word menus with the Excel menus. You can now edit the cells without switching to another application.

In-place editing is the most obvious manifestation of what was previously called ”borrowing another application’s functionality.” For it to happen, both server and container applications must support OLE Automation.

OLE Automation

This method allows you to programmatically manipulate objects exposed by another application from within your Visual Basic applications. It’s also a standard that defines how code is shared between applications and how applications can be controlled from within other applications. For example where you copy a range of cells from an Excel spreadsheet onto a Word document, you embed the range of cells. With OLE Automation, your application can request that Excel perform some calculations and return the result to Word. For example, you can pass a table to Excel and request that Excel manipulate the numeric data in says that are not possible with Word’s tools and then return the processed data to Word. You’ll see examples of Visual Basic applications that control (or OLE automate, as it’s called) Excel and Word.

OLE Drag-and-Drop

This method allows you to pick up objects that ha ole been exposed in a server application and place or drop them into your container application. For example, you can create an-embedded object in a Word document by dragging-and-dropping a range of cells from an worksheet. you learned how to code drag-arid-drop operations. Later in this chapter, you’ll learn how to a drag a document, or part of .it,and drop it on a control that can recognize. both the data being
dropped and the control.

An Example of Embedding and Linking

Let’s look at an example of embedding and linking objects from a user’s point of view. To create a compound document with Word Pad, follow these steps:

  1. Choose Start > Programs> Accessories> WordPad.
  2. Choose Insert> Object to display the Insert Object dialog box, as shown.
  3. Check the Create from File option, and then click the Browse button.
  4. In the Browse dialog. box (which is identical to a File Open dialog box), select a bitmap image, and click ok <. The selected bitmap will be embedded in the Word Pad document

When you save the document, the bitmap is saved with it. Word Pad is the container application it contains the bitmap object, which is saved along with the document- If you edit the original bitmap, the contents of the Word Pad document won’t be affected.

If you check the Create New option on the Insert Object dialog box, you’ll-see a list of object known to the system. Every application that can act as a server application the objects it exposes with the system, so that every container application can when you insert a new object, the application that knows how to handle it , with a new document. Go back to the Insert Object dialog box, check the option Create New, and from the Object Types list select Bitmap Image. By
default, bitmap images are handled by Paint. If you haven’t changed the application associated with bitmap images, Word Pad will contact Paid and ”borrow” its user interface. Word Pad’s menu will be replaced by Paint’s menu and Paint’s toolbox will appear on the screen. You can create a new bitmap with Paint’s tools as usual, only the process will take place from within Word Pad. You won’t have to start another application, copy the bitmap, and then paste it to the other application.

Regardless of whether you inserted a new bitmap or an existing one, to edit l’t, simply double-click the image. The operating system searches the Registry to find an application associated with bitmaps. The default application is Paint, which comes with Windows. If you haven’t changed this setting, the Paint application starts, and its,menus and tool bars appear in place of Word Pad menus. You can edit the bitmap and then return to the main document by clicking somewhere outside the image. Paint is the server application that knows how to manipulate bitmaps.

The bitmap in the Word Pad document and the bitmap in the disk file are two separate objects. You can change the disk file, even remove it from the disk, and the Word Pad document won’t be affected. What you have in the Word Pad documents a copy of the bitmap.

Furthermore, you can edit the embedded object in the same window that contains it. You don’t need to understand which program created which object, nor do you have to work with that object in a separate window. You can remain in the window of the container application and edit the object without switching applications or windows. One benefit of this approach is that it makes it easy to resize the object with respect to the surrounding text.

If you click the Link check box in the Insert Object dialog box, the object in the Word Pad document will be linked to the original object. When linking an object, there will be only one object (bitmap file) in the system. Word Pad will contain a reference to it, not a copy of the object.The same object can be linked to another document, perhaps with a different application. No matter how many documents make references to .this object, there will be a single object in the system. If this object is updated, all documents that reference this object will see its updated version.

Posted on November 6, 2015 in OLE Automation and VBA

Share the Story

Back to Top