Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I make RTTI-call with safecall function method of interface?

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 :-(

like image 423
Mielofon Avatar asked Feb 21 '13 06:02

Mielofon


1 Answers

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.

like image 166
David Heffernan Avatar answered Nov 04 '22 01:11

David Heffernan