<div dir="ltr"><div class="gmail_quote">On Tue, Jun 19, 2012 at 10:38 AM, Ludo Brands <span dir="ltr"><<a href="mailto:ludo.brands@free.fr" target="_blank">ludo.brands@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> As Bern said you can't call an object method without passing<br>
> the reference to the instance. In this case you are lucky<br>
> because TMyClass.SayHi doesn't use any properties or class<br>
> vars. Add a property to TMyClass and try to writeln that<br>
> property and you will see it fails. What you are doing here<br>
> is calling SayHi as if it where a class method.<br>
><br>
<br>
</div>Here is the correct way of doing it:<br>
<div class="im"><br>
function ExecMethod(Instance : TObject; Name : String) : Boolean;<br>
</div>type<br>
TProc= procedure of object;<br>
var<br>
method : TMethod;<br>
exec:tproc;<br>
begin<br>
method.Data := Pointer(Instance);<br>
method.Code := Instance.MethodAddress(Name);<br>
Exec:=TProc(Method);<br>
Result := Assigned(method.Code);<br>
if Result then Exec;<br>
end;<br>
<br>
Output:<br>
<div class="im"><br>
>From MyClass : Hi World from 482800<br>
</div>Hi World from 482800<br>
<div class="im">>From MyClass2 : Hi World from 482816<br>
</div>Hi World from 482816<br>
<div class="HOEnZb"><div class="h5"><br>
Ludo<br></div></div></blockquote><div><br>Thank you Ludo, Mattias and Bernd.<br>It works well now :)<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="HOEnZb"><div class="h5">
<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br><br>Ido<br></div>