Creating Clients for Servers That Do Not Have a Type Library

From RAD Studio
Jump to: navigation, search

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

  1. Place a TOleContainer component on your form.
  2. Set the AllowActiveDoc property to true if you want to host an Active document.
  3. Set the AllowInPlace property to indicate whether the hosted object should appear in the TOleContainer, or in a separate window.
  4. Write event handlers to respond when the object is activated, deactivated, moved, or resized.
  5. 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.
  6. 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.
  7. 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.
  8. When you want to release the server object, call the DestroyObject method.

See Also