![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Both embedded objects and linked objects originate in the server application that exposed it. Consider a Microsoft Excel spreadsheet object. Whether linked or embedded, the object becomes a part of the container application, but in different ways:
Obviously, whether you use linking or embedding depends upon the specific situation. Linking permits data from a single source to be automatically updated in one or more container applications that depend on it. This sounds similar to DDE, but OLE has an advantage over DDE: An OLE container has quick and direct access to the server application for modification of the linked data. Embedding is not useful for automatic updating of data, because only one application (the container) has access to the data. You use embedding when you want to provide a single application (the container) with access to the data manipulation and presentation abilities of a variety of server applications. At the risk of generalizing, DDE is most suitable when program code needs access to the data; OLE is preferable when you need only to display the data and edit it using the original application. Like all generalizations, exceptions surely exist, but this generalization serves as a pretty good guide.
OLE Containers In Visual BasicOne of the delights of Visual Basic programming is that previously complex tasks are rendered easy or even trivial. Implementing an OLE container is no exception. You let a controlin this case, the OLE Container controldo the work for you. This control has many properties that you have already used with other controls, such as those controlling its size and visibility. Several specialized properties also relate specifically to OLE, which we will cover in this section.
The Windows RegistryFor a Visual Basic programor any program, for that matterto act as an OLE container, it must know which OLE server applications are available. A container application cannot assume that a particular server application is available. Information about OLE servers is kept in the Windows registry. This information is maintained automatically. When an OLE server is installed, part of the installation process consists of registering the server by placing certain information in the registry. This information includes the server command line, the OLE protocols it supports, the class names of the objects it supports, and so on. This, of course, is exactly the information required by any program trying to establish itself as an OLE container. By obtaining this information from the registry, a container application can be sure that it will attempt to establish an OLE relationship only with servers that are available. A Visual Basic program uses the OLE control to access the registry.
Inserting An OLE ObjectThe OLE control permits an OLE object to be inserted during program design (by the programmer) or while the program is running (by the user). Of course, the program must include the code for the latter action. At runtime, the OLE process can be controlled by the user working with dialog boxes or by program code setting properties of the OLE control. Depending on the circumstances, one of these methods will be more appropriate. Inserting an object into an OLE container can be accomplished three ways. These three methods apply to both linking and embedding:
You can use these three methods of inserting OLE objects at both design time and runtime. Inserting An Object At Design TimeIf you insert an OLE object at design time, the link is fixed to the specified object and cannot be switched to another object while the program is running. For example, if you want a specific Excel workbook linked to or embedded in your Visual Basic application each and every time it runs, you would use this approach. To insert an object during program design, place an OLE control on the form. When you do so, Visual Basic will display the Insert Object dialog box, as shown in Figure 10.2. If you want to create a new, blank object, select the type of object from the list, then click on the OK button (remember, new objects can only be embedded, not linked). The server application associated with the selected object will start, and a blank object will display in the OLE controlor in its own window if you selected the Display As Icon option. Use the applications tools and commands to create and edit the data, or leave the object blank. The server applications menu is displayedwithout the File menu. Because the data object is embedded and will be stored within the OLE container, you have no need for the File menu commands. The exact details depend on the specific server. If you insert an Excel spreadsheet, for example, a grid of cells displays in the OLE control and the Excel menu appears at the top of the Visual Basic form. In any case, you can click on the form outside the OLE control to return to Visual Basic program design. If you want to insert an object from an existing file, select the Create from File option in the Insert Object dialog box. The dialog box will change, as shown in Figure 10.3. Enter the name of the desired file in the File box, or click on the Browse button to select the file. Click on the Link option to link the object; otherwise, the object will be embedded. Click on the OK button, and the selected object will be displayed in the OLE control. If you select an invalid fileone that is not associated with a registered OLE serveran error message will be displayed.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |