You need to look at the compiled code. I would expect that a
cast/QueryInterface is done behind the scenes by the compiler.
It is possible given the declaration of ISecondDescendant, that IFirst...
may be implemented. The compiler at the call point to DoSomething, does not
know the reference was derived from TNewClass. As you mention I would expect
a nil reference to be passed in.
Myles
=========
If I define a procedure
DoSomething(AObject : IFirstDescendant);
and
TNewClass = class(TInterfacedObject,ISecondDescendant);
and then the following code compiles okay
procedure Test;
var
MyObject : ISecondDescendant;
begin
MyObject := TNewClass.Create;
DoSomething(MyObject);
end;
I haven't checked yet, but I'm assuming the MyObject passed through to
procedure DoSomething() is then "nil", since TNewClass doesn't support
IFirstDescendant. Would that be your guess too? So why does it compile? On
the otherhand, does the ISecondDescendant pointer get sucessfully converted
to a IFirstDescendant pointer, in which case, why does
MyObject.QueryInterface(IFirstDescendant,FirstObject) return a "nil" pointer
to FirstObject?
However, if I define
IFirstDescendant = interface(IInterface);
ISecondDescendant = interface(IInterface);
ie. no interface inheritance - (or whatever you want to call it)
and
TNewClass = class(TInterfacedObject,IFirstDescendant,ISecondDescendant);
the Test() procedure does not compile. Any comments?
---------------------------------------------------------------------------
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"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
---------------------------------------------------------------------------
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"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/