[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Jim Mack

4/5/2012 4:31:00 PM

I have this working after a slight hiccup, but I'm curious if anyone
can explain what's going on in this situation. I'm a pragmatist at
heart -- if it works, move on -- but I do like to know what's under the
hood.

In a project with a form and a module, I do all the real work in a loop
(state machine) in the module, but I need the form to host two WMP
(media player) controls, in a control array.

To avoid having to always reference the form when manipulating them, I
Dim an array of the same type in the module and Set into the variables
a reference to the controls on the form. In the module:

Private LocalForm As frmHost
Private WMP(0 To 1) As WindowsMediaPlayer
...
...
Sub Main
Set LocalForm = New frmHost
Load LocalForm
Set WMP(0) = LocalForm.Player(0)

Now WMP(0) can access Player(0)'s properties and invoke its methods.
Very standard stuff, works as expected.

But not quite -- some of the properties aren't available to the local
reference. For example, this is setting up a player:

With WMP(0) ' This is the local reference
.uiMode = "none"
.stretchToFit = True
.URL = m_ClipNames(m_CurrentClip)
.settings.Volume = 50
Duration(m_CurrentClip) = .Controls.currentMedia.duration
End With

' HOWEVER --

With LocalForm.Player(0) ' This is the original
.Left = 0
.Top = 0
.Width = m_Width
.Height = m_Height
End With

The second set of properties is not available via WMP (the copy), only
via the original control. It hasn't escaped my notice that these are
all "UI" properties, likely added by some wrapper.

I'm sure there's a simple explanation, but I don't know enough about
what happens behind the scenes to figure it out. Any insight would be
appreciated.

--
Jim


31 Answers

ralph

4/5/2012 4:50:00 PM

0

On Thu, 05 Apr 2012 12:31:03 -0400, Jim Mack <no-uce-ube@mdxi.com>
wrote:

>I have this working after a slight hiccup, but I'm curious if anyone
>can explain what's going on in this situation. I'm a pragmatist at
>heart -- if it works, move on -- but I do like to know what's under the
>hood.
>
>In a project with a form and a module, I do all the real work in a loop
>(state machine) in the module, but I need the form to host two WMP
>(media player) controls, in a control array.
>
>To avoid having to always reference the form when manipulating them, I
>Dim an array of the same type in the module and Set into the variables
>a reference to the controls on the form. In the module:
>
> Private LocalForm As frmHost
> Private WMP(0 To 1) As WindowsMediaPlayer
> ...
> ...
> Sub Main
> Set LocalForm = New frmHost
> Load LocalForm
> Set WMP(0) = LocalForm.Player(0)
>
>Now WMP(0) can access Player(0)'s properties and invoke its methods.
>Very standard stuff, works as expected.
>
>But not quite -- some of the properties aren't available to the local
>reference. For example, this is setting up a player:
>
> With WMP(0) ' This is the local reference
> .uiMode = "none"
> .stretchToFit = True
> .URL = m_ClipNames(m_CurrentClip)
> .settings.Volume = 50
> Duration(m_CurrentClip) = .Controls.currentMedia.duration
> End With
>
>' HOWEVER --
>
> With LocalForm.Player(0) ' This is the original
> .Left = 0
> .Top = 0
> .Width = m_Width
> .Height = m_Height
> End With
>
>The second set of properties is not available via WMP (the copy), only
>via the original control. It hasn't escaped my notice that these are
>all "UI" properties, likely added by some wrapper.
>
>I'm sure there's a simple explanation, but I don't know enough about
>what happens behind the scenes to figure it out. Any insight would be
>appreciated.

Because the object references are not the same. They are declared as
two separate 'interfaces', albeit they are supported by the same
object.

All VB Object References actually refer to, is declared as, an
"Interface". This

Karl E. Peterson

4/5/2012 4:57:00 PM

0

Jim Mack wrote :
> The second set of properties is not available via WMP (the copy), only via
> the original control. It hasn't escaped my notice that these are all "UI"
> properties, likely added by some wrapper.

Relevant?

http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....

--
..NET: It's About Trust!
http://vfre...


ralph

4/5/2012 6:51:00 PM

0

On Thu, 05 Apr 2012 09:56:58 -0700, Karl E. Peterson <karl@exmvps.org>
wrote:

>Jim Mack wrote :
>> The second set of properties is not available via WMP (the copy), only via
>> the original control. It hasn't escaped my notice that these are all "UI"
>> properties, likely added by some wrapper.
>
>Relevant?
>
>http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....


Highly relevant.

Mercifully <g> my reply was truncated. I attempted to explain the
same, but of course, typically for me, in a manner more likely to
confuse than enlighten - as I went off detailing COM Interface
Aggregation and the joint psychosis between owners, containers, and
the contained.

I like MS's version better. Call them "extended properties" and be
done with it. There is a lesson to be learned there, but I doubt I
will. <bg>

-ralph

Jim Mack

4/5/2012 8:06:00 PM

0

> Jim Mack wrote :
>> The second set of properties is not available via WMP (the copy), only
>> via the original control. It hasn't escaped my notice that these are
>> all "UI" properties, likely added by some wrapper.
>
> Relevant?
>
> http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....

Great, I knew it had to be something like that. I'm not sure how, when
Setting the local copy = the form copy of the object, VB 'knew' that it
should assign only the underlying interface. I suppose the "As..."
referenced type only exposes that interface, so that's what it takes
on. I do wish I had a deeper grasp of all this.

I wonder what would happen if I Dimmed the local copy As Object? Hmmm,
I'll try that -- any predictions? Besides 'no Intellisense'?

--
Jim


Karl E. Peterson

4/5/2012 10:29:00 PM

0

Jim Mack explained :
>> Jim Mack wrote :
>>> The second set of properties is not available via WMP (the copy), only via
>>> the original control. It hasn't escaped my notice that these are all "UI"
>>> properties, likely added by some wrapper.
>>
>> Relevant?
>>
>> http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....
>
> Great, I knew it had to be something like that. I'm not sure how, when
> Setting the local copy = the form copy of the object, VB 'knew' that it
> should assign only the underlying interface. I suppose the "As..." referenced
> type only exposes that interface, so that's what it takes on. I do wish I had
> a deeper grasp of all this.
>
> I wonder what would happen if I Dimmed the local copy As Object? Hmmm, I'll
> try that -- any predictions? Besides 'no Intellisense'?

Won't work. <g> Matt Curland could tell you, in exquisite detail, why.
But I'd have left for the buffet before he finished.

I played around too much with UserControls to assume much of anything.
We tried to offer some stuff on the CCRP controls that was just more
deeply confounding then I could cope with, and it all involved those
damned Extender thingies in one manner or another. (Wish I could be
more precise, but it's been over 10 years since I really thought about
it.)

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

4/5/2012 10:30:00 PM

0

Jim Mack formulated on Thursday :
>> Jim Mack wrote :
>>> The second set of properties is not available via WMP (the copy), only via
>>> the original control. It hasn't escaped my notice that these are all "UI"
>>> properties, likely added by some wrapper.
>>
>> Relevant?
>>
>> http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....
>
> Great, I knew it had to be something like that. I'm not sure how, when
> Setting the local copy = the form copy of the object, VB 'knew' that it
> should assign only the underlying interface. I suppose the "As..." referenced
> type only exposes that interface, so that's what it takes on. I do wish I had
> a deeper grasp of all this.
>
> I wonder what would happen if I Dimmed the local copy As Object? Hmmm, I'll
> try that -- any predictions? Besides 'no Intellisense'?

Ahhh, but, perhaps you could get a reference to the control's
Container, then iterate it's Controls collection, and ... <vbg>

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

4/5/2012 10:32:00 PM

0

Karl E. Peterson submitted this idea :
> Jim Mack formulated on Thursday :
>>> Jim Mack wrote :
>>>> The second set of properties is not available via WMP (the copy), only
>>>> via the original control. It hasn't escaped my notice that these are all
>>>> "UI" properties, likely added by some wrapper.
>>>
>>> Relevant?
>>>
>>> http://msdn.microsoft.com/en-us/library/aa733622%28v=vs....
>>
>> Great, I knew it had to be something like that. I'm not sure how, when
>> Setting the local copy = the form copy of the object, VB 'knew' that it
>> should assign only the underlying interface. I suppose the "As..."
>> referenced type only exposes that interface, so that's what it takes on. I
>> do wish I had a deeper grasp of all this.
>>
>> I wonder what would happen if I Dimmed the local copy As Object? Hmmm, I'll
>> try that -- any predictions? Besides 'no Intellisense'?
>
> Ahhh, but, perhaps you could get a reference to the control's Container, then
> iterate it's Controls collection, and ... <vbg>

Totally shooting from the lip...

WMP.Container.Controls("Player").Left

? (Sorry, making myself <LOL> here...)

--
..NET: It's About Trust!
http://vfre...


Jim Mack

4/5/2012 11:24:00 PM

0

>>> Jim Mack wrote :
>>
>> I wonder what would happen if I Dimmed the local copy As Object? Hmmm,
>> I'll try that -- any predictions? Besides 'no Intellisense'?
>
> Won't work. <g> Matt Curland could tell you, in exquisite detail, why.
> But I'd have left for the buffet before he finished.

Yes, I've been there. MEGO.

The interesting news is that it did work. As expected, no Intellisense,
but replacing "As WindowsMediaPlayer" with "As Object" didn't affect
the running of it none, and when I then replaced the form.player
reference with the local reference, it continued to work just fine.

In that context I then went back to "As WindowsMediaPlayer" and sure
enough, up popped "Object does not support that property...".

So the local, specific object understands what limited interface it
should accept from the form copy and present to the user. A generic
object copy apparently can access the 'top level' or container
interface.

And now that I know that... <shrug> (-:


--
Jim


Karl E. Peterson

4/5/2012 11:56:00 PM

0

Jim Mack was thinking very hard :
>>>> Jim Mack wrote :
>>>
>>> I wonder what would happen if I Dimmed the local copy As Object? Hmmm,
>>> I'll try that -- any predictions? Besides 'no Intellisense'?
>>
>> Won't work. <g> Matt Curland could tell you, in exquisite detail, why.
>> But I'd have left for the buffet before he finished.
>
> Yes, I've been there. MEGO.
>
> The interesting news is that it did work. As expected, no Intellisense, but
> replacing "As WindowsMediaPlayer" with "As Object" didn't affect the running
> of it none, and when I then replaced the form.player reference with the local
> reference, it continued to work just fine.
>
> In that context I then went back to "As WindowsMediaPlayer" and sure enough,
> up popped "Object does not support that property...".
>
> So the local, specific object understands what limited interface it should
> accept from the form copy and present to the user. A generic object copy
> apparently can access the 'top level' or container interface.

Wow! Well, you surprised me with that.

> And now that I know that... <shrug> (-:

I don't know why, but I'm reminded of that Laugh-In bit, with the
little German guy (Arte Johnson?)... Heh.

--
..NET: It's About Trust!
http://vfre...


Bob Butler

4/6/2012 12:41:00 AM

0


"Jim Mack" <no-uce-ube@mdxi.com> wrote in message
news:7fqdnSw4ucsctOPSnZ2dnUVZ_i2dnZ2d@giganews.com...
>>>> Jim Mack wrote :
>>>
>>> I wonder what would happen if I Dimmed the local copy As Object? Hmmm,
>>> I'll try that -- any predictions? Besides 'no Intellisense'?
>>
>> Won't work. <g> Matt Curland could tell you, in exquisite detail, why.
>> But I'd have left for the buffet before he finished.
>
> Yes, I've been there. MEGO.
>
> The interesting news is that it did work. As expected, no Intellisense,
> but replacing "As WindowsMediaPlayer" with "As Object" didn't affect the
> running of it none, and when I then replaced the form.player reference
> with the local reference, it continued to work just fine.
>

How about "As Control"?