[fpc-pascal] Dynamically Execute method
nc-gaertnma at netcologne.de
Tue Jun 19 09:37:39 CEST 2012
On Tue, 19 Jun 2012 00:22:29 +0300
ik <idokan at gmail.com> wrote:
> I'm playing a bit with the notion of execute a method dynamically on demand.
> I'ved created the following PoC:
> It works, but for some strange reason, I find myself feeling that I'm
> missing something, or it should be done differently.
> Does this code written properly, or should I do it differently ?
function ExecMethod(Instance : TObject; Name : String) : Boolean;
var Exec : TMethod;
Exec.Code := TProcedure(Instance.MethodAddress(Name));
Exec.Data := Instance;
Result := Assigned(Exec.Code);
if Result then TProcedureOfObject(Exec)();
More information about the fpc-pascal