Skip to content

Instantly share code, notes, and snippets.

@MeirKriheli
Created June 18, 2012 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeirKriheli/2950980 to your computer and use it in GitHub Desktop.
Save MeirKriheli/2950980 to your computer and use it in GitHub Desktop.
{$mode objfpc}{$M+}
program test;
type
TMyClass = class
// Must be with RTTI view
procedure SayHi;
end;
procedure TMyClass.SayHi;
begin
writeln('Hi World');
end;
var
MyClass : TMyClass;
Exec : procedure of object;
found : Boolean;
begin
MyClass := TMyClass.Create;
TMethod(Exec).data := MyClass;
TMethod(Exec).code := MyClass.MethodAddress('SayHis');
found := Assigned(Exec);
if not found then
begin
writeln(STDERR, 'Could not find method');
else
Exec;
end;
MyClass.Free;
halt(Integer(not found));
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment