Nice try, but I still get different addresses. I am still casting them to Interfaces just out of interest and again, even though the underlying object is the same, when I put the mouse over u1 I get TInterfacedObject(X) as IUnknown and over u2 I get TInterfacedObjectDescendant(X) as IUnknown. So I think the VarData(v1).VUnknown is pointing to a different place in the object's RTTI table (or whatever interfaces point to) than v2. This must have something to do with how the item was stored in the variant to start with. Maybe I'll try tracking that down.... thanks, Phil. Myles Penlington <[EMAIL PROTECTED]> on 08/08/2000 11:11:42 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]: Variant comparison. how? 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 --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz