Board index » delphi » Help on OLE Automation Objects: Properties and Methods

Help on OLE Automation Objects: Properties and Methods

I am trying to find out the exposed methods and properties of OLE
automation objects.

How do you do something like this with delphi?

I imagine that I will have to use the IDispatch interface and somehow
QueryInterface to find out what the Properties and Methods are.

I am not sure where to go.  I can create a reference to the object,
using:

OleObject : OleVariant;

procedure Button1Click(Sender : TObject);
begin
  OleObject := CreateOleObject(OleAutoObjectName);
end;
.
.
.

But what do I need to do to create a list of the properties and
methods that are useable for this object.

Any help would be greatly appreciated.

Jason T. Ashmead

 

Re:Help on OLE Automation Objects: Properties and Methods


Quote
In article <34C17F48.7A3F6...@ash.net>, Brinn wrote:
> I am trying to find out the exposed methods and properties of OLE
> automation objects.

Having an object reference will let yet you call things, but first you
have to know what to call.

You'll need documentation or a typelib.  If you've got a typelib,
which can be a .tlb, .olb or an embedded resource in an exe or dll,
open it in Delphi and you'll get a list of the methods and arguments.

Re:Help on OLE Automation Objects: Properties and Methods


I have seen/used TypeLibs before, but that is not really what I am
trying to do.  In Visual Basic, there is a powerful Object Browser.
If you have used it, you will know that it brings up a list of all the
properties and methods of classes in a variety of OLE Objects.
For example, WINWORD.EXE.

I am trying to write something comparable in Delphi, as an EXE or a
wizard, to help me in development.  I was hoping there was a way to
query the Object itself to determine what properties/methods, and what
parameters of its methods it accepts.

Maybe I just need a better understanding of what the ObjectBrowser in
VB is doing.  Do you think that it is reading TypeLibs and/or embedded
resource info from the exe/dll?

If so, then how is that done?  I have seen the GetTypeInfo routine, so
that must be for reading info from a TypeLib.  But what about the
embedded Resource info?  Is that accessed via standard Resource calls,
ie GetIconFromResource???

Is there any other way?

Jason

Quote
Scott Samet [TeamB] wrote:

> In article <34C17F48.7A3F6...@ash.net>, Brinn wrote:

> > I am trying to find out the exposed methods and properties of OLE
> > automation objects.

> Having an object reference will let yet you call things, but first you
> have to know what to call.

> You'll need documentation or a typelib.  If you've got a typelib,
> which can be a .tlb, .olb or an embedded resource in an exe or dll,
> open it in Delphi and you'll get a list of the methods and arguments.

Re:Help on OLE Automation Objects: Properties and Methods


Quote
In article <34C1C6F1.56643...@ash.net>, Jason T. Ashmead wrote:
> Maybe I just need a better understanding of what the ObjectBrowser in
> VB is doing.  Do you think that it is reading TypeLibs and/or embedded
> resource info from the exe/dll?

I'm virtually certain that the only way to get the info is from a
typelib, so that would have to be the way it's doing it.  

Quote
> If so, then how is that done?  I have seen the GetTypeInfo routine, so
> that must be for reading info from a TypeLib.  But what about the
> embedded Resource info?  Is that accessed via standard Resource calls,
> ie GetIconFromResource???

I'm not sure of the details as to how its actually done.  I know TypeLib
info is pretty complex and it takes both Delphi and Microsoft's OLEView
utility several seconds to open and format a typelib.  I also know that
the documentation is poor and Borland has run into problems because MS
distributes typelibs that violate their own published specs.  I suggest
you start by going to the MS website and checking if the distribute the
source to OLEVIEW.  I'm sure it's in C/C++ but it's likely to be the
best "documentation" for what you're trying to do.

A couple things to note:  There's a "hidden" flag in the typelib, much
like a file's hidden flag.  It seems that borland honors the flag and
does not display the type in the Project Import | TypeLib list.  MS's
OLEVIEW does not honor the flag and displays it.  So you will probably
see more things in the MS list.   Also, OLEVIEW displays the typelib in
MS MIDL format, while Delphi displays it in Pascal.  The general
structure should be similar.

Re:Help on OLE Automation Objects: Properties and Methods


You can do this at runtime assuming the object you are querying has type
library (like Microsoft word).  The trick is that you need to get a pointer
to the ITypeInfo and ITypeLib interfaces defined for the object you are
interested in.  Look at the OLE Programmers Reference help file that ships
with Delphi 3 and C++ Builder  - it is invaluable.  If somehow you don't
have this file go to the Microsoft Developers Network and do a search on
ITypeInfo.  You'll find the same information on-line.

Basically, what you need to do is (I haven't looked up the exact syntax, so
sorry if I make a mistake - the process is correct however):

var
   Dispatch: IDispatch;
    typeInfo: ITypeInfo;
    typeLib: ITypeLib;
    Word: OleVariant;
begin
//create object you are interested in
Word:=CreateOleObject("Word.Application")

//get dispatch interface
Dispatch:=Word as IDispatch

//get type info
oleCheck(Dispatch.GetTypeInfo(TypeInfo,GetThreadLocale,0));

//load type lib
oleCheck(TypeInfo.GetContainingTypeLib(TypeLib,0)

Then interate through the typelibrary using the functionality built into the
ITypeLib interface.  For each interface or co-class in the type library
you'll need a ITypeInfo interface.  Use this interface to find out the
number of properties, methods, what the method arguments are, etc., etc.,
etc.

Hope that gets you started.

Charlie Savage
c...@interserv.com

Quote
Jason T. Ashmead wrote:
> I have seen/used TypeLibs before, but that is not really what I am
> trying to do.  In Visual Basic, there is a powerful Object Browser.
> If you have used it, you will know that it brings up a list of all the
> properties and methods of classes in a variety of OLE Objects.
> For example, WINWORD.EXE.

> I am trying to write something comparable in Delphi, as an EXE or a
> wizard, to help me in development.  I was hoping there was a way to
> query the Object itself to determine what properties/methods, and what
> parameters of its methods it accepts.

> Maybe I just need a better understanding of what the ObjectBrowser in
> VB is doing.  Do you think that it is reading TypeLibs and/or embedded
> resource info from the exe/dll?

> If so, then how is that done?  I have seen the GetTypeInfo routine, so
> that must be for reading info from a TypeLib.  But what about the
> embedded Resource info?  Is that accessed via standard Resource calls,
> ie GetIconFromResource???

> Is there any other way?

> Jason

> Scott Samet [TeamB] wrote:

> > In article <34C17F48.7A3F6...@ash.net>, Brinn wrote:

> > > I am trying to find out the exposed methods and properties of OLE
> > > automation objects.

> > Having an object reference will let yet you call things, but first you
> > have to know what to call.

> > You'll need documentation or a typelib.  If you've got a typelib,
> > which can be a .tlb, .olb or an embedded resource in an exe or dll,
> > open it in Delphi and you'll get a list of the methods and arguments.

Other Threads