The function being called looks exactly like this:

function TJavaUtilList.add(p1: OleVariant): WordBool;
begin
  TOLECollectionItem(FCollection.Add).Value := p1;
  result := True;
end;

The call to the function looks exactly like this:

     ICollection.Add(OLEVariant(NewObject as IUnknown));

where ICollection is supported by TJavaUtilList. I don't think I need the
explicit cast but the problem was still there without it.

If I put a break point on the begin in the add method and try casting p1 to an
IUnknown, it is nil. meanwhile the underlying object has had it's reference
count incremented.

I'm bamboozled.

thanks,

Phil.




Myles Penlington <[EMAIL PROTECTED]> on 07/08/2000 14:51:07

Please respond to [EMAIL PROTECTED]

To:   Multiple recipients of list delphi <[EMAIL PROTECTED]>
cc:    (bcc: Phillip Middlemiss/NZ Forest Research Institute/NZ)

Subject:  RE: [DUG]: Aaarrgh! Variants@#%^$3!!



> However, the basic problem is still that passing an IUnknown to a method
> expecting a variant seems to fail. The call goes through allright, but
> casting
> the variant back to an IUnknown returns an unnassigned interface.
>> What happens if you put a break point on the assignment in the collection
item? Is the variant NIL?
It should not be, else all I could say is that the problem lies elsewhere.

> Does casting an interface to a variant increment the reference count? that
> could
> be the problem?
>> It could be a problem, but the interface would still NOT be NIL. Have not
looked at the compiled code to see what happens.

Myles.




> Myles Penlington <[EMAIL PROTECTED]> on 07/08/2000 12:25:35
>
> Please respond to [EMAIL PROTECTED]
>
> To:   Multiple recipients of list delphi <[EMAIL PROTECTED]>
> cc:    (bcc: Phillip Middlemiss/NZ Forest Research Institute/NZ)
>
> Subject:  RE: [DUG]:  Aaarrgh! Variants@#%^$3!!
>
>
>
> Don't quite see why you are using variants in this case, but it should not
> make any difference.
>
> MyList.add(aNewObject as IUnknown)
>
> This is the line you need to check. Does AnewObject support the IUnknown
> interface?
> It would appear from your comments that it does not.
>
> I would probably use Interface variables rather than Variants by
> preference.
> The only reason to use OLEVariants would be if you are going to pass the
> object reference to VBScript/JScript eg ASP/OleAutomation.
>
> eg MyList.Add( AInterface: IUnknown);
>
> "My stubs are descended from TInterfacedObject but implement stub methods
> for
> IDispatch. "
>
> Why do this?? Seems a complete waste of time. Does not achieve anything.
> Your comment previous to this does however make complete sense, but it
> does
> not require this to be done.
>
> Myles.
>
>
> > -----Original Message-----
> > From:   [EMAIL PROTECTED]
> > [SMTP:[EMAIL PROTECTED]]
> > Sent:   Monday, August 07, 2000 11:58 AM
> > To:     Multiple recipients of list delphi
> > Subject:     [DUG]:  Aaarrgh! Variants@#%^$3!!
> >
> >
> >
> > Hi all,
> >
> > I am writing a client GUI that is talking to a number of Java servers
> via
> > J-Integra (therefore COM) although that is really only background and
> not
> > vital
> > to the problem.
> >
> > I have written stubs for all the classes that I need from the servers so
> I
> > can
> > build the GUI without the servers needing to be up to date or even
> > running.My
> > stubs are descended from TInterfacedObject but implement stub methods
> for
> > IDispatch.
> >
> > The problem boils down to storing the stub objects in a list that deals
> > with
> > OLEVariants. The List uses a TCollectionItem internally, storing each
> > added
> > variant inside a TCollectionItem descendant that holds onto an
> OLEVariant.
> > Adding a new item to the list looks like this:
> >
> > MyList.add(aNewObject as IUnknown)
> >
> > which automatically casts the IUnknown to an OLEVariant which the Add
> > method is
> > expecting. The Add method assigns the OLEVariant to a newly created
> > CollectionItem descendant.
> >
> > However! Inside the add method, before I do anything, in the
> > Evaluate/Modify
> > dialog, I cast the passed OLEVariant back to an IUnknown and it informs
> me
> > that
> > it is nil!!!!
> >
> > Is this because the IDispatch interface is stubbed so therefore not a
> real
> > ActiveX object? or am I just missing something with variants? This is my
> > first
> > time using them.
> >
> > Any help would be great,
> >
> > cheers,
> >
> > Phil Middlemiss.
> >
> >
> >
> --------------------------------------------------------------------------
> > -
> >     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> --------------------------------------------------------------------------
> -
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
>
>
>
>
>
>
> --------------------------------------------------------------------------
> -
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz






---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to