property的使用(事件可能就是回调函数)
TOnUserInfoShow = procedure(userName:string;userAge:Integer)of object;//定义事件模型中的回调函数原型
TUserInfo = class
private
FName:string;
FAge:Integer;
FOnUserInfoShow: TOnUserInfoShow;
procedure FSetAge(theAge:Integer);
public
property Name:string read FName;//只读属性(私有变量)
property Age:Integer read FAge write FSetAge;//读写属性(私有变量,私有方法)
property OnUserInfoShow:TOnUserInfoShow read FOnUserInfoShow write FOnUserInfoShow;//事件模型回调函数
constructor Create;
end;
Ps: 对于FAge,FSetAge等变量和方法,只需在property后声明好,直接Ctrl+shift+c,即可自动生成。
二.只读属性
构造函数
constructor TUserInfo.Create;
begin
Self.FName:='Terry';
Self.FAge:=20;
end;
读取只读属性
begin
Self.Memo1.Lines.Add('读取只读属性姓名:'+Self.theUserInfo.Name);
end;
运行
三.读写属性
构造函数
constructor TUserInfo.Create;
begin
Self.FName:='Terry';
Self.FAge:=20;
end;
修改读写属性,并读取新值
begin
Self.Memo1.Lines.Add('修改前的读写属性年龄为:'+inttostr(Self.theUserInfo.Age));
Self.theUserInfo.Age:=30;
Self.Memo1.Lines.Add('修改后的读写属性年龄为:'+inttostr(Self.theUserInfo.Age));
end;
运行
四.事件回调函数
主窗体成员函数
procedure TFrmMain.UserInfoShow(name: string; age: Integer);
begin
Self.Memo1.Lines.Add('用户姓名为:'+Self.theUserInfo.Name);
Self.Memo1.Lines.Add('用户年龄为:'+inttostr(Self.theUserInfo.Age));
end;
主窗体创建时,将函数指针赋值给“事件回调函数”
调用事件回调函数
begin
Self.theUserInfo.OnUserInfoShow(Self.theUserInfo.Name,Self.theUserInfo.Age);
end;
运行
http://blog.csdn.net/zisongjia/article/details/53674036
property的使用(事件可能就是回调函数)的更多相关文章
- C# dll 事件执行 js 回调函数
C# dll 事件执行 js 回调函数 前言: 由于js 远程请求 XMLHttpRequest() 不支持多线程,所以用C# 写了个dll 多线程远程抓住供js调用. 最初代码为: C#代 ...
- socket.io笔记二之事件监听回调函数接收一个客户端的回调函数
//服务端 socket.on('test', function (name, fn) { console.log(name) //输出yes fn('woot'); }); //客户端 socket ...
- C#将C++动态库的回调函数封装成事件
关于C#调用C++动态库的文章很多,调用动态库中回调函数的方法也不在少数.但大多数调用回调函数的方法依然保留了C++的语法特点. 比如有一段C++的回调函数代码,为了表达它的意思,我把注释也粘贴了进来 ...
- Node.js:创建应用+回调函数(阻塞/非阻塞)+事件循环
一.创建应用 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi.从这个角度看,整个"接收 HTTP ...
- Node js 安装+回调函数+事件
/* 从网站 https://nodejs.org/zh-cn/ 下载 这里用的 9.4.0 版本 下载完安装 安装目录是 D:\ApacheServer\node 一路默认安装 安装后打开cmd命令 ...
- 小兔JS教程(三)-- 彻底攻略JS回调函数
这一讲来谈谈回调函数. 其实一句话就能概括这个东西: 回调函数就是把一个函数当做参数,传入另一个函数中.传进去的目的仅仅是为了在某个时刻去执行它. 如果不执行,那么你传一个函数进去干嘛呢? 就比如说对 ...
- C++ 回调函数 实现 的测试代码
最近项目里使用了异步Socket,使用的是完成端口做的e; Accept,receive,send 等完全的异步实现(多线程) 然后 又要多个端口使用, 后来想到包装下完成端口Socket,然后当有事 ...
- jQuery的deferred对象详解 jquery回调函数
http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html jQuery的 ...
- 回调函数与DOM事件
原文:http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/ 先看如下代码: document.addEventListener(&q ...
随机推荐
- navigator 页面链接
页面链接. 属性名 类型 默认值 说明 url String 应用内的跳转链接 redirect Boolean false 是否关闭当前页面 hover-class String navigat ...
- ES数据
通过Elasticsearch使用的你的数据 Elasticsearch 系列导航 elasticsearch 与 elasticsearch-head 的安装 ElasticSearch Index ...
- Android SDK location should not contain whitespace, as this cause problems with NDK tools
解决方案一: The easiest solution is to move the SDK somewhere else, where there is no space or other whit ...
- unity3d 学习笔记(三)
工作现场查看: 飞行模式: 按住鼠标右键 w s a d 围绕浏览当前视图, q e 上下浏览. 交模式下无效 需透视图 移动吸附:移动状态(w) ctrl+shif 移动吸附在其它物体上移动 顶点 ...
- wpf mvvm模式下CommandParameter传递多参
原文:wpf mvvm模式下CommandParameter传递多参 CommandParameter一般只允许设置一次,所以如果要传递多参数,就要稍微处理一下.我暂时还没找到更好的方案,下面介绍的这 ...
- linux awk(good)
一个用awk处理字符串的例子: #!/bin/bash source="nokia201703148855" preffixStr=$(echo $source |awk '{pr ...
- WPF旋转的界面实现
原文:WPF旋转的界面实现 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/details/1821534 ...
- wpf实现仿qq消息提示框
原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...
- cocos2d 滚动背景 举 无限
void Bird::update(float time){ auto bg=this->getChildByTag(200); auto bg1=this->getChildByTag( ...
- SVN如何迁徙到Git
由于一直都是采用SVN作为源码管理,转到Git不能从头开始吧~~下面就具体说说如何将SVN已有的项目工程迁徙到Git上面 步骤 (1) 安装Git客户端程序(2) 将SVN上面的工程通过Git克隆到本 ...