博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
问题-MethodAddress返回NIL?MethodAddress与published的关系?
阅读量:7009 次
发布时间:2019-06-28

本文共 1146 字,大约阅读时间需要 3 分钟。

问题现象:有位朋友(397085381)在Q群里问“为什么书上的可以访问,而自己写的代码访问时为nil”

问题原因:因为要用“Self.MethodAddress('Test')”访问,方法必须放在“published”下。

问题处理:增加“published”就好了。

解答人员:541011510、316405484、397085381。

 

实例代码:

1 unit Unit2; 2  3 interface 4  5 uses 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7   Dialogs, StdCtrls; 8  9 type10   TTest = procedure of object;11   TForm2 = class(TForm)12     Button1: TButton;13     procedure Button1Click(Sender: TObject);14   private15     {
Private declarations }16 public17 published//使用MethodAddress必须定义在发布区的方法18 procedure Test;19 {
Public declarations }20 end;21 22 var23 Form2: TForm2;24 25 implementation26 27 {
$R *.dfm}28 29 procedure TForm2.Button1Click(Sender: TObject);30 var31 oP: TMethod;32 otest: Ttest;33 begin34 oP.Data := Pointer(Self);35 op.Code := Self.MethodAddress('Test');//使用MethodAddress必须定义在published(发布区)的方法36 // op.Code := @TForm2.test; //什么方法都可以返回地址37 if Assigned(op.Code) then38 begin39 otest := Ttest(op);40 otest;41 end; 42 end;43 44 procedure TForm2.Test;45 begin46 ShowMessage('Test');47 end;48 49 end.
View Code

 

转载地址:http://anttl.baihongyu.com/

你可能感兴趣的文章
对我而言晦涩的递归
查看>>
React Native 从入门到原理
查看>>
iOS如何随意的穿插跳跃,push来pop去
查看>>
使用maven编译Java项目 http://www.tuicool.com/articles/YfIfIrq
查看>>
Strut2中的session和servlet中的session的区别
查看>>
自定义adapter实现listview双列显示
查看>>
MyBatis——实现关联表查询
查看>>
struts2的MVC模式
查看>>
cocos2d-x JS 复选按钮checkBox的单选与多选
查看>>
表格花式效果
查看>>
Thrift 基于zookeeper改造模式
查看>>
rsync与cwRsync
查看>>
图像的形态学处理
查看>>
Elasticsearch5.5 部署Head插件
查看>>
VC++使用IMAPI调用Outlook邮箱客户端和Foxmail邮箱客户端遇到的问题
查看>>
Python字符编码以及循环机制介绍
查看>>
ON_COMMAND ON_MESSAGE ON_NOTIFY区别与联系
查看>>
远程服务调用RPC框架介绍,微服务架构介绍和RPC框架对比,dubbo、SpringClound对比...
查看>>
golang学习笔记9 beego nginx 部署 nginx 反向代理 golang web
查看>>
接口测试基础
查看>>