![]() Last edit: 99-02-03 Graham Wideman |
Visio + Delphi |
GWVisio_Demo: Initial Design Decisions Article created: 99-02-01 |
You can build your Visio Automation Controller ("Automation Client") as either a "VSL" or as a stand-alone program. A VSL is really nothing more than a DLL which shows up on one of Visio's menus, and Visio can load it on demand. Generally this is the way to go if you want the tightest integration with Visio. However, there are a couple of disadvantages:
So, for simplicity and flexibility, the demo is a stand-alone application.
Automation Controllers use variables to reference OLE objects within the automation server (in this case Visio), such as Application, Document, Page, Shape, Cell and so forth. OLE defines three approaches for this:
Approach | Advantages | Disadvantages |
OLE Variant: The controller's variables are declared as OLE Variants, and each method or property reference is resolved at run time. | No need to work with Type Libraries. | Compiler can't check your references -- chief source of bugs won't be checked until runtime. In addition, resolving references at runtime is slow. |
"dispinterfaces" | Faster than OLE Variant | Slower and not as smart as interfaces |
"interfaces" | Resulting app is faster. Code is cleaner. Makes maximum use of compiler's ability to check your references. | You have to use Type Library -- can you click a couple of buttons? |
Needless to say, this example uses Type Libraries.
Visio offers two different ways for a controller to get notifications of events, which I'll call the "ConnectionPoint" and "AddAdvise" approaches.
Approach | Advantages | Disadvantages |
Connection Point: Controller basically registers for all available notifications. Controller's event-response code decides which notifications to actually do something about. | Simple to code. | Every available event results in a notification call from Visio to controller. Because this is potentially time consuming, there are some events that Visio doesn't offer this way -- they are available only through the AddAdvise method. |
AddAdvise: Controller registers only for the exact events it wants to see. | Visio doesn't waste time calling controller for events that are not of
interest. Some events are only available by this method. |
Since this is a less orthodox approach, code to do this is not widely available, and the translation from Visio's C++ example is tricky. (This example shows how.) |
This demo shows how to use the AddAdvise method.
For more information on the Connection Points method, see Binh Ly's excellent info and code generator, here. I've tried it on Visio and it indeed works.
For info on which events are available via each method, I've summarized them here, and they are covered in detail in the Visio Automation Reference help file.
Go to: Up to: [Visio] [GWVisio Demo for Delphi]