我如何用接口的safecall函数方法进行RTTI调用?

Mie*_*fon 15 delphi rtti delphi-xe2 delphi-xe3

我有这个测试程序https://gist.github.com/real-mielofon/5002732

  RttiValue := RttiMethod.Invoke(RttiInstance, [10]);
Run Code Online (Sandbox Code Playgroud)

和带接口的简单单元:

unit Unit163;

interface

type
{$M+}
  ISafeIntf = interface
    function TestMethod(aI: integer): integer; safecall;
  end;
{$M-}
 type
   TSafeClass = class(TInterfacedObject, ISafeIntf)
   public
     function TestMethod(aI: integer): integer; safecall;
   end;

implementation

function TSafeClass.TestMethod(aI: integer): integer;
begin
  result := aI+1; // Exception !!
end;

end.
Run Code Online (Sandbox Code Playgroud)

我有kaboom

result := aI+1;
Run Code Online (Sandbox Code Playgroud)

如果它是程序或不安全,那么它没关系:-(

Dav*_*nan 5

现在我自己尝试了这个,并查看了代码,我的结论是有一个bug.RTTI单元确实尝试执行safecall方法重写.它似乎弄错了.我建议您提交您的项目作为QC报告,并通过解决该问题stdcall与HRESULT返回值.