[fpc-pascal] casting interfaces and objects

Graeme Geldenhuys graemeg.lists at gmail.com
Sun May 18 22:51:19 CEST 2008


2008/5/18 Marc Santhoff <M.Santhoff at t-online.de>:
> When using a cast from an interface to an object the compiler warns
> about the class types "TObject" and "IObserver" not being related.
>
> Since an implementor of in interface always will be a class type and any
> class type at least inherits from TObject, I assume it is okay?
>
> Is there a better method of handling this case?

Casting of Interfaces has always been known to me as a big NO-NO.  I
believe it's got something to do with how they are represented in the
VMT or method table or something like that. I don't know the compiler
internals. Why not simply use a InterfaceList or a generic Pointer
list (as to not increment the interface reference counter). You can
then add them to the list without having to cast to TObject.


Regards,
 - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list