[DUG] Interfaces

Richard Bullin Richard at lowmanconsulting.com
Thu Aug 7 15:07:05 NZST 2008



You've declared Res as being a IXMLResidentialType and then asking if
IXMLResidentialType implements Iauctionable, which it doesn't.

You need to make res a TXMLResidentialType as below


var
  Res : TXMLResidentialType;
  Auctionable : IAuctionable;
begin
  Res := TXMLResidentialType.Create;
  if Res.QueryInterface(IAuctionable, Auctionable) = 0 then
    ShowMessage('Auctionable');


That should work


Regards
 
Richard Bullin
B.E.(Hons) - Mechatronics                        
Lowman Consulting Ltd            
Ph       +64 9 535 8647
Cell     +64 21 053 6127
Skype  Richard.Bullin
Web     www.framecad.com

-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
On Behalf Of Myles Penlington
Sent: Thursday, 7 August 2008 2:56 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Interfaces

Should work as is by the looks of it.
Could also try 

If supports( res, IAuctionable, Auctionable ) then ...

I would debug/step into the QueryInterface method and then check the
actual classname of the object you are dealing with to see if it is
actually TXMLResidentialType.

You could always also implement IInterface/IUnknown and provide another
version of QueryInterface (which I have done on many an instance). 

Interfaces ... lots of fun!

Myles. 

-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
On Behalf Of Alister Christie
Sent: Thursday, 7 August 2008 2:47 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Interfaces

I'm having some fun with interfaces

I have two interfaces IXMLResidentialType and IAuctionable.
I have a class which implements these two interfaces TXMLResidentialType
= class(TXMLNode, IXMLResidentialType, IAuctionable)

...

I have some code
var
  Res : IXMLResidentialType;
  Auctionable : IAuctionable;
begin
...
  if Res.QueryInterface(IAuctionable, Auctionable) = 0 then
    ShowMessage('Auctionable');

What I'm trying to determine is if Res implements IAuctionable - which
it does (through TXMLResidentialType which effective Res is an instance
of), however IXMLResidentialType doesn't seem to realise this.  How do I

make this work?

Does this question make any sense?

If I'm not able to do this it's not too much of a problem, but will mean

a bunch of duplicated code.


--
Alister Christie
Computers for People
Ph: 04 471 1849 Fax: 04 471 1266
http://www.salespartner.co.nz
PO Box 13085
Johnsonville
Wellington 

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe

Attention:
This communication is confidential and may be legally privileged.  If
you are not the intended recipient, please do not use, disclose, copy or
distribute it, other than to return it to us with your confirmation that
it has been deleted from your system.

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe



More information about the Delphi mailing list