Wilfred Verkley asked:

> Im having some trouble type-converting OleVariants (OleDeviants would
> probably be more correct).
>
> I have an OleVariant reference which i know points to a IStream
> object.  How can I convert this to a variable of IStream?
>
> i.e.
>
> var
>   ref1 : OleVariant;
>   ref2 : IStream;
> begin
>   ref2 := IStream (ref1); // doesnt work
> end;

I've been there and suffered with this small section of Delphi. As far as
I can make out from testing the only things that you can safely convert a
Variant or OleVariant into are IUnknown and IDispatch, which are the
interface types that variants can store.

So the cleanest way to do what you want is something like:

  var
    ref1: OleVariant;
    unk1: IUnknown;
    ref2: IStream;
  begin
    unk1 := ref1;        // clean convesion to IUnknown
    if Supports(unk1, IStream, ref2) then
      ; // Life is good
    else
      raise Exception.Create('Who passed me that stuff!');
  end;

you might even be able to get away with simply

  if Supports(ref1, IStream, ref2) then

as the OleVariant should be cleanly converted into an IUnknown and then
fired down into the Supports utility function.

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"

Reply via email to