打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
call Delphi methods by name

call Delphi methods by name

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.

Published methods

The method presented only works with published procedures and functions.

Access Errors

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.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
《Mastering Delphi 6》学习笔记之九
[emacs][delphi] 跳到函数声明/实现
Access中使用Create Procedure创建存储过程第1/2页
oracle如何调用存储过程? Oracle / 开发 - CSDN社区 communit...
Delphi 2009 的反射单元(ObjAuto):
如何编写数据库存储过程?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服