How to set object class type for OLE automation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set object class type for OLE automation

Frank Sonnemans-2
When testing Dolphin for the development of an OLE automation client I
ran into some trouble. I need to communicate with an OLE server (Act
2000) to access the database. The problem starts when I connect to a
IDispatch interface through a property of my main application object.
I think that I need to set the object type explicitly to allow certain
overloaded functions to work.

For example:

"Connect to ACT and open database"
db := ActOleIDatabase new.
db open: 'c:\actdb\test.dbf'.
db validateUser: 'Frank Sonnemans' sPassword: ''.

db isOpen.

"get contact IDispatch interface of type ActOleIContact"
contacts := db contact.
contacts moveFirst.

"get first contacts name"
contacts data: 26.

------------
The result

IDispatch(ExternalStructure)>>hresultError:
IDispatch>>invokeId:flags:parms:retVal:
IDispatch>>invokeId:flags:parms:
IDispatch>>doesNotUnderstand:
UndefinedObject>>{unbound}doIt
CompiledExpression>>value:
SmalltalkWorkspace>>evaluateRange:ifFail:debug:
SmalltalkWorkspace>>evaluateRange:ifFail:
SmalltalkWorkspace>>displayIt
Symbol>>forwardTo:

------------
If I look at the definition of the data: method of the ActOleIContact
method I see:
data: nField
        "Answer the <variant> value of the 'Data' property of the receiver."

        ^(self getPropertyId: 308 item: nField)

Executing this manually for the contact object works:
contacts getPropertyId: 308 item: 26.

My conclusion is that the wrong method gets called because the system
does not know the class type of the contacts object.

So how do I tell the system which class the object belongs to?

Regards,


Frank


Reply | Threaded
Open this post in threaded view
|

Re: How to set object class type for OLE automation

bmurphy
I'm still learning the automation stuff, but I believe
     contacts := db contact asImplType.
will work. Anyone is free to correct this if it is wrong!

Brian Murphy-Dye

[hidden email] (Frank Sonnemans) wrote in message news:<[hidden email]>...

> When testing Dolphin for the development of an OLE automation client I
> ran into some trouble. I need to communicate with an OLE server (Act
> 2000) to access the database. The problem starts when I connect to a
> IDispatch interface through a property of my main application object.
> I think that I need to set the object type explicitly to allow certain
> overloaded functions to work.
>
> For example:
>
> "Connect to ACT and open database"
> db := ActOleIDatabase new.
> db open: 'c:\actdb\test.dbf'.
> db validateUser: 'Frank Sonnemans' sPassword: ''.
>
> db isOpen.
>
> "get contact IDispatch interface of type ActOleIContact"
> contacts := db contact.
> contacts moveFirst.
>
> "get first contacts name"
> contacts data: 26.
>
> ------------
> The result
>
> IDispatch(ExternalStructure)>>hresultError:
> IDispatch>>invokeId:flags:parms:retVal:
> IDispatch>>invokeId:flags:parms:
> IDispatch>>doesNotUnderstand:
> UndefinedObject>>{unbound}doIt
> CompiledExpression>>value:
> SmalltalkWorkspace>>evaluateRange:ifFail:debug:
> SmalltalkWorkspace>>evaluateRange:ifFail:
> SmalltalkWorkspace>>displayIt
> Symbol>>forwardTo:
>
> ------------
> If I look at the definition of the data: method of the ActOleIContact
> method I see:
> data: nField
> "Answer the <variant> value of the 'Data' property of the receiver."
>
> ^(self getPropertyId: 308 item: nField)
>
> Executing this manually for the contact object works:
> contacts getPropertyId: 308 item: 26.
>
> My conclusion is that the wrong method gets called because the system
> does not know the class type of the contacts object.
>
> So how do I tell the system which class the object belongs to?
>
> Regards,
>
>
> Frank


Reply | Threaded
Open this post in threaded view
|

Re: How to set object class type for OLE automation

Don Rylander-3
In reply to this post by Frank Sonnemans-2
Frank,
"Frank Sonnemans" <[hidden email]> wrote in message
news:[hidden email]...
[...]
> "get contact IDispatch interface of type ActOleIContact"
> contacts := db contact.
> contacts moveFirst.
>
> "get first contacts name"
> contacts data: 26.
[...]

I'd guess that you're getting an IDispatch rather than an ActOleIContact.
Display the result of evaluating

    contacts class

If it's IDispatch, try this:

    contacts := db contact queryInterface: ActOleIContact.

and then check the class again.  There are other ways to make sure you're
getting the right class, but that's probably the simplest.

Don


Reply | Threaded
Open this post in threaded view
|

Re: How to set object class type for OLE automation

Frank Sonnemans-2
Don,

You where right it was an IDispatch. Your suggestion solved the problem.

Thanks!

"Don Rylander" <[hidden email]> wrote in message news:<9oq659$eta47$[hidden email]>...

> Frank,
> "Frank Sonnemans" <[hidden email]> wrote in message
> news:[hidden email]...
> [...]
> > "get contact IDispatch interface of type ActOleIContact"
> > contacts := db contact.
> > contacts moveFirst.
> >
> > "get first contacts name"
> > contacts data: 26.
> [...]
>
> I'd guess that you're getting an IDispatch rather than an ActOleIContact.
> Display the result of evaluating
>
>     contacts class
>
> If it's IDispatch, try this:
>
>     contacts := db contact queryInterface: ActOleIContact.
>
> and then check the class again.  There are other ways to make sure you're
> getting the right class, but that's probably the simplest.
>
> Don


Reply | Threaded
Open this post in threaded view
|

Re: How to set object class type for OLE automation

Blair McGlashan
Frank, Don

You in message news:[hidden email]...
> Don,
>
> You where right it was an IDispatch. Your suggestion solved the problem.
>
> Thanks!
>
> "Don Rylander" <[hidden email]> wrote in
message news:<9oq659$eta47$[hidden email]>...
> > ...[snip]....
> > If it's IDispatch, try this:
> >
> >     contacts := db contact queryInterface: ActOleIContact.
> >
> > and then check the class again.  There are other ways to make sure
you're
> > getting the right class, but that's probably the simplest.
> >
> > Don

Brian's suggestion of using #asImplType is a slightly simpler way to achieve
the same effect if the COM object in question has type information (which is
likely). It amounts to the same thing (a "down cast"), if you trace it
through.

Regards

Blair