How to cast a Interface to a Object in Delphi

前端 未结 6 1031
南旧
南旧 2020-12-01 18:39

In delphi 2009 I have a reference to a IInterface which I want to cast to the underlying TObject

Using TObject(IInterface) obv

6条回答
  •  天命终不由人
    2020-12-01 19:08

    Hallvard's hack is very specific to how the Delphi compiler generates code. That has been remarkably stable in the past, but it sounds like they changed something significant in Delphi 2009. I only have 2007 installed here, and in that, Hallvard's code works fine.

    Does GetImplementingObject return NIL?

    If so, then if you debug and set a break-point on the case statement in the GetImplementingObject routine, what does the value of QueryInterfaceThunk.AddInstruction evaluate to in the debugger?

提交回复
热议问题