I have this test program https://gist.github.com/real-mielofon/5002732
RttiValue := RttiMethod.Invoke(RttiInstance, [10]);
and simple unit with 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.
and I have kaboom on
result := aI+1;
if it is procedure or isn't safecall, then it's all right :-(
Having now tried this myself, and looked at the the code, my conclusion is that there is a bug. The RTTI unit does indeed attempt to perform safecall
method re-writing. It just appears to get it wrong. I recommend that you submit your project as a QC report, and workaround the problem by using stdcall
with HRESULT
return values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With