Board index » delphi » Calling OLE Automation methods at run-time

Calling OLE Automation methods at run-time

Hi Mike,

you can derive your comobject from IDispatch and provide those methods
with specific names as "GetCompanyName" and "GetThisCompanyName". You'd
then have to find out the dispid with "GetIdsOfNames" (method of
IDispath). A Diskid is simply a numerical id which identifies a method or
property. Then call "Invoke" with this dispid.

It's a bit of a hack, but it works. I've done it in C++ before, but never
tried in Delphi (should work, though).

Good luck,

Rudi

Mike Senkovich schrieb:

Quote
> Hi.

> I wanted to know if anyone has any insights on if I might be able to
> call Ole automation methods at run-time instead of hard-coding them at
> design time.

> We have the same set of tasks that we would like to perform on several
> Contact Management systems (such as ACT and Aurum), both of which are
> OLE Automation servers.  We would like to be able to save the OLE
> statement representing GetCompanyName in a file or database so that we
> don't necessarily have to provide custom programming to interact with
> a new system explicitly.  If the "GetCompanyName" equivalent for ACT
> is "GetThisCompany" and the equivalent for Aurum is
> "GetThisCompanyName", then if we can pull the contact
> management-specific string from a database then we don't necessarily
> have to change any Delphi code to do this once the generic interface
> is in place.

> I understand that something like
> fOLEObject:=CreateOLEObject(something) is usually used and then the
> methods of this fOLEObject are hard coded in Delphi.

> Any ideas?

> Thanks in advance!
> -Mike

 

Re:Calling OLE Automation methods at run-time


Hi.

I wanted to know if anyone has any insights on if I might be able to
call Ole automation methods at run-time instead of hard-coding them at
design time.

We have the same set of tasks that we would like to perform on several
Contact Management systems (such as ACT and Aurum), both of which are
OLE Automation servers.  We would like to be able to save the OLE
statement representing GetCompanyName in a file or database so that we
don't necessarily have to provide custom programming to interact with
a new system explicitly.  If the "GetCompanyName" equivalent for ACT
is "GetThisCompany" and the equivalent for Aurum is
"GetThisCompanyName", then if we can pull the contact
management-specific string from a database then we don't necessarily
have to change any Delphi code to do this once the generic interface
is in place.

I understand that something like
fOLEObject:=CreateOLEObject(something) is usually used and then the
methods of this fOLEObject are hard coded in Delphi.

Any ideas?

Thanks in advance!
-Mike

Re:Calling OLE Automation methods at run-time


Hello,

As Rudolf suggests you can implement IDispatch binding. However, to
generically make a call at runtime through IDispatch, you will have to
manually build the parameters array and make the GetIdsOfNames and Invoke
calls yourself. My tutorial on automation might give you some hints:

http://www.castle.net/~bly/Programming/Delphi/Automation

have fun
--
Binh Ly
Brickhouse Data Systems, Inc.
http://www.brickhouse.com

Quote
Mike Senkovich wrote in message <365c5816.6923...@forums.borland.com>...
>Hi.

>I wanted to know if anyone has any insights on if I might be able to
>call Ole automation methods at run-time instead of hard-coding them at
>design time.

>We have the same set of tasks that we would like to perform on several
>Contact Management systems (such as ACT and Aurum), both of which are
>OLE Automation servers.  We would like to be able to save the OLE
>statement representing GetCompanyName in a file or database so that we
>don't necessarily have to provide custom programming to interact with
>a new system explicitly.  If the "GetCompanyName" equivalent for ACT
>is "GetThisCompany" and the equivalent for Aurum is
>"GetThisCompanyName", then if we can pull the contact
>management-specific string from a database then we don't necessarily
>have to change any Delphi code to do this once the generic interface
>is in place.

>I understand that something like
>fOLEObject:=CreateOLEObject(something) is usually used and then the
>methods of this fOLEObject are hard coded in Delphi.

>Any ideas?

>Thanks in advance!
>-Mike

Re:Calling OLE Automation methods at run-time


Many thanks to both of you for your responses.

Using the tutorial as a guide I was able to get the DispID using
GetIDsOfNames-- very smooth.  

It looks like I will still have to pass the GUID of the Automation
server I want to access to GetIDsOfNames.  Any ideas how to get the
GUID if I know the ClassName of the Automation Server I want to call?

Also, do you know of code samples I could use as a guide to manually
build the parameters array?  I'm having a tough time figuring out what
goes into the rgvarg, rgdispidNamedArgs, cArgs and cNamedArgs
parameters-- I tried unsuccessfully to invoke a multiply method in a
COM object I created-- the method just needs two integer params and
returns an integer.  I haven't found much in the Delphi help/code
samples about TDispParams.

By the way, the tutorial is superb-- I learned quite a bit from it!

Thanks again!
-Mike

Quote
On Mon, 30 Nov 1998 22:39:01 -0500, "bly" <b...@castle.net> wrote:
>Hello,

>As Rudolf suggests you can implement IDispatch binding. However, to
>generically make a call at runtime through IDispatch, you will have to
>manually build the parameters array and make the GetIdsOfNames and Invoke
>calls yourself. My tutorial on automation might give you some hints:

>http://www.castle.net/~bly/Programming/Delphi/Automation

>have fun

Re:Calling OLE Automation methods at run-time


Hello,

Quote
Mike Senkovich wrote in message <36665929.4315...@forums.borland.com>...
>Many thanks to both of you for your responses.

>Using the tutorial as a guide I was able to get the DispID using
>GetIDsOfNames-- very smooth.

>It looks like I will still have to pass the GUID of the Automation
>server I want to access to GetIDsOfNames.  Any ideas how to get the
>GUID if I know the ClassName of the Automation Server I want to call?

You mean the GUID parameter? Unless you implement your own GetIdsOfNames
handler on the server side, you can just pass GUID_NULL to that and it is
understood that you want the default automation interface. If you really
want to get the guids of implemented interfaces for a coclass, you can use
the ITypeInfo interface that IDispatch.GetTypeInfo returns. You have to
learn how to use ITypeInfo though. Consult the Automation Programmers
Reference (MS Press) for this.

Quote
>Also, do you know of code samples I could use as a guide to manually
>build the parameters array?  I'm having a tough time figuring out what
>goes into the rgvarg, rgdispidNamedArgs, cArgs and cNamedArgs
>parameters-- I tried unsuccessfully to invoke a multiply method in a
>COM object I created-- the method just needs two integer params and
>returns an integer.  I haven't found much in the Delphi help/code
>samples about TDispParams.

You can study the DispatchInvoke procedure code in ComObj.pas - its a bit
complicated. A good reference is the the Automation Programmers Reference -
examples are in C++ but should be readily translatable to Delphi.

Quote
>By the way, the tutorial is superb-- I learned quite a bit from it!

thanks

Quote

>Thanks again!
>-Mike

have fun
binh

Other Threads