Newbie: COM objects iteration method

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

Newbie: COM objects iteration method

Syver Enstad-3
As far as I can see (and that might be short indeed) there is no
Smalltalkish implementation of the Dispatch collection methods.

It would be nice if the ActiveX Component Wizard would generate
something like (below) for COM objects that implement the Dispatch
collection interface. As the table below shows all the methods used
in the implementation of do: are mandatory methods for a Dispatch/Automation
collection (whether it turns out to be true in the real world I don't
know). I guess I'll see soon.

It seems TkindDispatchAnalyzer and superclasses would be the natural
place for implementing the generation of this method. I will just hack
it in somewhere, but if anyone has some suggestions on a clean/nice
way to implement it I am all ears

do: aBlock
        | count |
        count := 1.
        [count <= self count] whileTrue: [aBlock value: (self item: count).
                                          count := count + 1]

<Snipped from MSDN, definition of a Dispatch collection>
A collection is exposed from Automation through a collection
object. There is no "collection object" type. Collection objects can
be pseudo-objects; that is, it is reasonable for collection objects to
exist only while a client is iterating over the collection.

The following table shows the standard properties and methods of a collection object. Note that some are optional:

Member Description Optional?
Add     method      Adds the indicated item to the collection. Yes
Count   property    Returns the number of items in the collection. No
Item    method      Returns the indicated item in the collection, or VT_EMPTY if the item does not exist. No
_NewEnum property   Returns an OLE object that supports IEnumVARIANT. This method is not visible to users. No
Remove method       Removes the specified item from the collection. Yes

--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Newbie: COM objects iteration method

Syver Enstad-3
Syver Enstad <[hidden email]> writes:

I've hacked in generation of do: methods for Automation collections in
AXInterfaceTypeAnalyzer.
 
do: aBlock
        | index |
  index := 1.
  [index <= self count] whileTrue: [
                aBlock value: (self item: index). index := index + 1]

For some COM objects I had to insert a runtime test at the top of the method:

self isVBCollection ifFalse: [^nil].

This was because we don't know if they are collection at compile
time. The ifFalse: part should probably raise an exception
instead. Does anybody know of a suitable exception to throw if we find
out at runtime that an object actually doesn't support enumeration but
the client has called the method anyway?

Btw, Dolphin must be one of the best way of getting to know a COM
object. It's extremely nice to be able to call a method on a COM
object and then just browse the class of the return value from the
method. Great stuff!


--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Newbie: COM objects iteration method

Syver Enstad-3
And then I found out that it was already implemented by
Dispatch>>contents. Now well, That's one way of getting to know
>>Dolphin's COM support classes ;-).
--

Vennlig hilsen

Syver Enstad