I don't know how many other COM libraries do this, but
specifically with iTunes, the Interfaces defined for
tracks form a hierarchy (in python-speak):
The problem is, a number of interfaces are defined to
return a pointer to a Track interface when in fact one
can test the object and safely refer to it via a
derived interface. For instance,
iTunesApp.CurrentTrack returns a Track interface
pointer, even if it is a FileOrCDTrack. In fact, all
but 1 interface prevents the user from accessing the
derived class properties (which include a lot of new
features that are part of the base class in
AppleScript). Direct Indexing by name, ID or playlist
order all return a pointer to the base interface.
Thus, none of these allow access to the derived
attributes in FileOrCDTrack even if the track is indeed
a File or CD based track. So the ONLY way to retrieve
the derived interface is to use the Enum method of the
LibraryPlaylist object and iterate through ALL the
tracks known, which in a large library can take an
astronomical amount of time. The Enum method does
however properly return FileOrCDTrack interfaces when
The idea of the Dynamic Cast would therefore be to
allow the user to perform a C++ style dynamic_cast on
an interface to convert it to a different interface.
In this example, one would take a track instance, call
it's 'kind' property to verify that it was a
FileOrCDTrack and then cast the interface pointer from
a Track interface to a FileOrCDTrack.
Log in to post a comment.