Max
Thanks, I will in my own defence say that 'COMb exposes a property a of
'type' COMa'
which is yes an interface
with the statement
>> COMb.a := COMa; // fails
I should have said this fails at runtime, it compiles OK
> COMa := CreateOLEObkect('COMa.Function') as IDispatch;
Makes no difference, the error (EOLEException), I get is 'Object Variable or
with block variable not set'
Since I can import the Type lib then IDispatch (ie dual) must supported and
both default interfaces inherit from IDispach
Oh well, The fun thing of course is that the VB programmer suggests you use
late binding because until
recently they didn't know how to stop VB reassigning TGUID's everytime they
compiled!
On a related subject has anyone read what M$ have done with the VB6 to
VB.NET port, its not backward
compatible all Variants -> Objects etc etc etc, I think with D6/Kylix/D6.NET
Borland should be running
Delphi for VB programmer courses
Neven
----- Original Message -----
From: Max Nilson <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Thursday, 29 March 2001 10:38
Subject: RE: [DUG]: COMmunication Breakdown
> Neven MacEwan asked a funkly COM question:
>
> > object COMa and COMb, COMb exposes a property a of 'type' COMa
> >
> > it works if I import the TL and use the CoClass create to
> > explicitly create an instance of COMa of the type interface
> > that COMb expects
>
> > but if I 'Late bind' ie let COM work it all out it fails
>
> OK, I'll have a stab at this one. COM doesn't have objects, it has
> interfaces, and this makes a large difference to behaviour earily vs late
> bound.
>
> When you earily bind all of the typing is working exactly as expected
> because Delphi is managing all the interfaces as their appropiate 'native'
> types.
>
> When you late bind Delphi must play some games with the typing. A Variant
> type can only store two different types of interface, IUnknown and
> IDispatch. So any time that you assign an interface into a variant delphi
> must type coerse the interfaces somehow. Its turns out that the rules are
> really simple for this coersion. If you assign an IDispatch then Delphi
> stores that, and if you store anything else that Delphi will query the
> interface IUnknown interface and store that.
>
> The upshot of this is that unless you are working with IDispatch that all
> interfaces stored in variants are IUnknowns. So when you try to assign
>
> COMb.a = COMa
>
> Delphi barfs because you can't to IDispatch property manipulation on the
> IUnknown in COMb.
>
> You can work arounf this if COMb inplements dual interfaces, that is both
> the native interface and also IDispatch, but you'll need to do code like:
>
> var
> COMa, COMb: variant;
>
> COMa := CreateOLEObkect('COMa.Function') as IDispatch;
> COMb := CreateOLEObkect('COMb.Function');
>
> COMb.a := COMa; // fails
>
> and you'll also have to hope that the COMb.a property does appropiate type
> coersion to query the appropiate interface that it wants when it gets an
> IUnknown passed into it. So unless the COM objects are written to be
> dispatched than you can't do late binding with them.
>
> > also when you create an interface in the first method how can
> > you free it.
> > ie you set a varient to NULL but do you assign an interface nil?
>
> Yes. Assiging nil to an interface is managed by Delphi so that interface
> you had there has Release called on it. If you have no other references to
> that interface then its going to destroy itself. This is one of the huge
> advantages that Delphi has over C, and that is the automatic management of
> interfaces and the AddRef and Release calls.
>
> Cheers, Max.
>
>
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"