Nasty stuff.
Variants dealing with non-object data is easy, objects and interfaces is a
different matter entirely
Technically, being nice the interfaces themselves have to implement a
function.
Otherwise to do a comparison or they return "Self" cast to an integer ...
etc. It's all hacks really.
For a dirty implementation try this.
Result := (TVarData( v1).VUnknown = TVarData( v2 ).VUnknown )
Myles.
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, August 08, 2000 9:41 AM
> To: Multiple recipients of list delphi
> Subject: [DUG]: Variant comparison. how?
>
>
>
> Hi all,
>
> I have a routine that has to check if two variants, v1 and v2, are holding
> interfaces to the same underlying object. I've tried the following
> approaches
> with the following results (assumption is that they do indeed point to the
> same
> underlying object:
>
> (1)
> result := v1 = v2; - runtime cast error
>
> (2)
> var
> u1, u2 : IUnknown;
> begin
> u1 := v1;
> u2 := v2;
> result := u1 = u2; - u1 and u2 have different
> addresses
>
> (3)
> <<cast to IUnknown same as 2>>
> result := @(Pointer(u1)^) = @(Pointer(u2)^) - u1 and u2 are pointing to
> different positions in the same object, eg u1 is a TInterfacedObject(X) as
> IUnknown and u2 is a TMyObject(X) as IUnknown. The interesting thing here
> is
> that the tool-tip given in the IDE when holding the mouse over each
> variable
> reports X as the same address - ie the same underlying object! I can't
> work out
> how to get that address in code though.
>
> Anybody come accross this before?
>
> cheers,
>
> Phil.
>
>
> --------------------------------------------------------------------------
> -
> 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