gpt4 book ai didi

delphi - 如何使用接口(interface)的 safecall 函数方法进行 RTTI 调用?

转载 作者:行者123 更新时间:2023-12-03 14:36:32 26 4
gpt4 key购买 nike

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

  RttiValue := RttiMethod.Invoke(RttiInstance, [10]);

和带有接口(interface)的简单单元:

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.

我打开了 kaboom

result := aI+1;

如果是过程或者不是安全调用,那就没问题了:-(

最佳答案

现在我自己尝试了这个,并查看了代码,我的结论是存在一个错误。 RTTI 单元确实尝试执行safecall 方法重写。看来只是搞错了。我建议您将项目作为 QC 报告提交,并使用 stdcallHRESULT 返回值来解决该问题。

关于delphi - 如何使用接口(interface)的 safecall 函数方法进行 RTTI 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14996078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com