Created
June 18, 2012 21:59
-
-
Save MeirKriheli/2950980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$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