[fpc-pascal] Casting descendant interface variables to base

cobines cobines at gmail.com
Mon Jan 31 07:28:11 CET 2011


2011/1/31 Andrew Hall <andrew.hall at shaw.ca>:
> Interfaces do not behave like classes.  Each each interface implemented/supported by a class is unique - at runtime a "descendent" interface is entirely unrelated to its ancestor.

Ok, so in this assignment

var
  iBase: IBaseInterface;
  iDesc: IDescInterface;
begin
  iBase             := iDesc;
end;

iBase still holds a pointer to IDescInterface of the class instance, but in this

begin
  iBase             := iDesc as IBaseInterface;
end;

it is now a pointer to IBaseInterface, because of implicit QueryInterface?

So, I think I can compare interface variables but first I have to
bring them to the same interface using "as", for example to IUnknown.

--
cobines



More information about the fpc-pascal mailing list