by Jan Verhoeven, 15 November 2002
In Delphi you can call published methods by name.
function TPascalServerF.ExecProc(MyProcStr : String):boolean;Var MyProc : procedure of object;Begin TMethod(myProc).data:=self; TMethod(MyProc).code :=MethodAddress(MyProcStr); result:=true; if not Assigned(MyProc) Then result:=false else MyProc;end;
The example code above is from my PascalServer program where I use a Pascal Script Interpreter thatgenerates an event each time an unknown identifier is encountered, allowing you to respond with you own code.
Because I wanted to avoid a lengthy sequence of if.. else statements, I needed a way tocall a method from the identifier name. The function listed above does exactly that.
The method presented only works with published procedures and functions.
Originally I did not use a procedure of object but just procedure and did not bother aboutallocating the implicit self. This seemed to work, untill I started calling other methods fromwithin the published method. Delphi was expecting a self pointer which was not there andgenerated an access error.
联系客服