Luca Olivetti wrote 17 lines
Hello,
I seldom use interfaces myself, though some components I need use them
extensively, and I find them difficult to debug.
I thought it was because gdb doesn't understand them, but I switched
to fpdebug a long time ago and it still find them problematic:
if I hover on an interface variable, the hint shows only the address.
The same happens if I put the variable in a watch or in evaluate/modify.
If I try "intfvariable as TRealClass" (in case I know the real class)
I get an error
Unexpected at xx: "as"
If I try TRealClass(intfvariable) I see bogus data.
Is this a known limitation or it's me doing it wrong?
The problem is that there is no formal way to get an object instance from any interface, because the compiler can not know what the interface might point to and even then it might not be an Object Pascal class instance, but instead e.g. a C++ instance or some static implementation like is used in rtl-generics or even multiple object instances if "implements" is involved.
Even "as" only works, because it internally uses
IInterface.QueryInterface with a special GUID that's handled by TInterfacedObject.QueryInterface thus it does not work with raw interfaces or types that provide their own QueryInterface implementation.
Regards,
Sven