Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sample exception in RTTI-call safecall function method of interface
program Project94;
uses
Winapi.Windows, System.SysUtils, System.Classes, System.Rtti,
System.Generics.Collections,
Unit163 in 'Unit163.pas';
procedure Main;
var
SafeIntf: ISafeIntf;
RttiContext: TRttiContext;
RttiType: TRttiType;
RttiMethod: TRttiMethod;
RttiValue: TValue;
RttiInstance: TValue;
begin
SafeIntf := TSafeClass.Create;
try
RttiContext.Create;
try
RttiType := RttiContext.FindType('Unit163.ISafeIntf');
RttiInstance := TValue.From<IInterface>(SafeIntf);
if RttiType <> nil then begin
try
for RttiMethod in RttiType.GetMethods do begin
if SameText(RttiMethod.Name, 'TestMethod') then begin
RttiValue := RttiMethod.Invoke(RttiInstance, [10]);
Break;
end;
end;
finally
RttiType.Destroy;
end;
end;
finally
RttiContext.Free;
end;
finally
SafeIntf := nil;
end;
end;
begin
Main;
end.
// Unit
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.