How to cast a Interface to a Object in Delphi

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

    var
      N, F: NativeInt; // NativeInt is Integer(in delphi 32bit ) 
      S: TObject;
    begin
      N := NativeInt(Args[0].AsInterface) - 12; 
      {subtract 12 byte to get object address(in x86 ,1 interface on class) }
      S := TObject(N);    
      writeln(S.ToString);
    
    end;
    

提交回复
热议问题