Creating Clients for Servers That Do Not Have a Type Library
Go Up to Creating COM Clients Index
Some older COM technologies, such as object linking and embedding (OLE), do not provide type information in a type library. Instead, they rely on a standard set of predefined interfaces. To write clients that host such objects, you can use the Vcl.OleCtnrs.TOleContainer component. This component appears on the System category of the Tool Palette.
TOleContainer acts as a host site for an Ole2 object. It implements the IOleClientSite interface and, optionally, IOleDocumentSite. Communication is handled using OLE verbs.
To use TOleContainer
- Place a TOleContainer component on your form.
- Set the AllowActiveDoc property to true if you want to host an Active document.
- Set the AllowInPlace property to indicate whether the hosted object should appear in the TOleContainer, or in a separate window.
- Write event handlers to respond when the object is activated, deactivated, moved, or resized.
- To bind the TOleContainer object at design time, right click and choose Insert Object. In the Insert Object dialog, choose a server object to host.
- To bind the TOleContainer object at run time, you have several methods to choose from, depending on how you want to identify the server object. These include CreateObject, which takes a program id, CreateObjectFromFile, which takes the name of a file to which the object has been saved, CreateObjectFromInfo, which takes a record containing information on how to create the object, or CreateLinkToFile, which takes the name of a file to which the object was saved and links to it rather than embeds it.
- Once the object is bound, you can access its interface using the OleObjectInterface property. However, because communication with Ole2 objects was based on OLE verbs, you will most likely want to send commands to the server using the DoVerb method.
- When you want to release the server object, call the DestroyObject method.