How to cast a Interface to a Object in Delphi

前端 未结 6 1035
南旧
南旧 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:16

    In short: you shouldn't or add an interface with a method that returns the pointer for you. Anything else is hackery.

    Note that an interface "instance" may be implemented in another language (they are COM compatible) and / or may be a stub for something out of process etc etc.

    All in all: an interface instance only agrees to the interface and nothing else, certainly not being implemented as a Delphi TObject instance

提交回复
热议问题