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

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

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

解答人员:541011510、316405484、397085381。

实例代码:

 unit Unit2;

 interface

 uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TTest = procedure of object;
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
published//使用MethodAddress必须定义在发布区的方法
procedure Test;
{ Public declarations }
end; var
Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject);
var
oP: TMethod;
otest: Ttest;
begin
oP.Data := Pointer(Self);
op.Code := Self.MethodAddress('Test');//使用MethodAddress必须定义在published(发布区)的方法
// op.Code := @TForm2.test; //什么方法都可以返回地址
if Assigned(op.Code) then
begin
otest := Ttest(op);
otest;
end;
end; procedure TForm2.Test;
begin
ShowMessage('Test');
end; end.

问题-MethodAddress返回NIL?MethodAddress与published的关系?的更多相关文章

  1. 解决NSData转NSString返回nil的问题

    // 字符串转Data NSString *str =@"jesfds"; NSData *data =[str dataUsingEncoding:NSUTF8StringEnc ...

  2. 解决 pathForResource 返回 nil的问题

    点击(此处)折叠或打开 NSString* path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@&quo ...

  3. Swift - 初始化方法返回nil表示初始化失败

    自Swift1.1开始,初始化init方法便有返回nil的能力.我们可以在init声明的时候在其后面加上一个 ? 或者 ! 来表示初始化失败时可能返回nil. 比如,给Int类添加一个将字符串初始化成 ...

  4. 为什么有时候NSData转换成NSString的时候返回nil

    为什么有时候NSData转换成NSString的时候返回nil 有时候,NSData明明有值,可是,当转换成NSString的时候,却没有值,现在来进行测试:) -现在提供测试用素材- 源码如下: / ...

  5. redis lpop key 当key不存在时,返回nil , 监测redis执行语句是否正常执行

    Lpop key 返回值: 列表的头元素. 当key 不存在时, 返回 nil . 需求:  开发在执行 lpop key 时, 出现问题 , 执行语句卡住, 不能执行下去 , 需对此做一个监测 由于 ...

  6. redis的lua脚本拓展,返回nil及其判断

    redis自带的lua脚本 127.0.0.1:6379> hget team wyc "{\"name\":\"wyycc\",\" ...

  7. 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil

    openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...

  8. 解决pathForResource返回nil, 无法读取plist文件问题

    有很多人在设置plist文件的时候, 会发现读取不了plist文件里面的内容, 返回值为nil, 下面我们来解决一下这个问题. 首先我们打开工程并且按照下面的步骤来设置: 设置好后, 我们来写一段代码 ...

  9. Swift - IBOutlet返回nil(fatal error: unexpectedly found nil while unwrapping an Optional value)

    在Swift 中 ViewController 默认构造方法不关联同名的xib文件 在使用OC的时候,调用ViewController的默认构造函数,会自动关联到一个与ViewController名字 ...

随机推荐

  1. 使用java修改图片DPI

    修改以后可以直接用PS打开看效果 全部使用rt下的类,无需下载其他jar包 import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.imag ...

  2. jquery.inputmask 输入框input输入内容格式限制插件

    jQuery Input Mask plugin http://robinherbots.github.io/jquery.inputmask README.md jquery.inputmask C ...

  3. xtrabackup-工作原理

    数据备份 xtrabackup是基于innodb的crash恢复功能之上的.它会拷贝innodb数据文件(这会导致数据不一致的),然后对文件执行crash恢复使其一致. 因为innodb维护了redo ...

  4. gtest测试代码编写思想

    mockXXX类 . testXXX类 . mock method 1. mockXXX 类,通常使用继承测试目标类的方法,来方便针对目标类的测试提供部分扩展功能,比如为protected 成员添加g ...

  5. FreeSWITCH呼叫参数之sip_cid_type

    这个参数定义了呼叫中主叫信息的头字段类型.支持两种类型: 1. rpidRemote-Party-ID头,这是默认的设置.{sip_cid_type=rpid}sofia/default/user@e ...

  6. Eclipse安装PlantUML插件

    新技术的诞生和更新,新工具的发现和使用是两件让人开心的事情. 还记得Visio下苦苦的画流程图的时光吗,现在一切都变得so easy,因为有PlantUML! 官网:http://plantuml.c ...

  7. python dict 和 json 互转

    在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作. 在Python中自带json库.通过import json导入. import json 在json模块有2个方 ...

  8. Java 8 forEach examples遍历例子

    1. forEach and Map 1.1 Normal way to loop a Map. Map<String, Integer> items = new HashMap<& ...

  9. django -- 为model 指定数据库名

    一.为model指定数据库名: django自己实现的ORM中.如果要指定一个model的表名是通过Meta类来实现的. from django.db import models # Create y ...

  10. unity, Collider2D.bounds的一个坑

    Note that this will be an empty bounding box if the collider is disabled or the game object is inact ...