Read the documentation. :-)
There are two ways to connect to an ActiveX server: at compile-time (early binding) or at run-time (late binding). There's [an article at MSDN that explains in more detail.
Early binding is what is used when you use typed variables (such as using the TWordApplication
or TExcelApplication
from the component palette). The type library is used to determine what types and interfaces are supported, and methods can be looked up using a DispInterface
from the v-table; the compiler can then validate that functions exist and check for typos and such, and figure out what's available for Code Completion and Code Insight).
Accessing an ActiveX server by way of a variant (as your code snippet demonstrates) is late binding
. Nothing is known to the compiler until the code is actually executed, at which point the methods are attempted to be called via an IDispatch
interface, and it either succeeds or fails at that point. Because the compiler knows nothing about what your variant might contain, there's no way to know at design or compile time what methods and types are available.
Because your code is using late binding, there's no way to know what properties might be available except for reading the documentation (or trial and error, of course, which isn't really an option). (The other alternative is to use early binding, if there's a type library available for the ActiveX server, at which point you stop using a variant and switch to an interface that the compiler can use to determine what's available to you.)