Delphi拾遗(8) 类事件
类的事件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyEvent = procedure of object; //不带参数的过程
TMyEventExt = procedure(AName: string) of object; //带参数的过程
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyBase = class
private
FName : string;
FAge : Integer;
FOnEvent: TMyEvent; //定义 TMyEvent 类型事件
FOnEventExt: TMyEventExt;
procedure SetAge(const AValue: Integer);
public
//创建类时进行相应的一些初始化工作
constructor Create;
procedure SetEvent1;
procedure SetEvent2;
procedure SetEventExt1(ATmp: string);
//Name属性 不可更改
property Name: string read FName write FName;
//Age属性 可以更改
property Age: Integer read FAge write SetAge;
//关联事件 发布 TMyEvent 类型事件
property OnEvent: TMyEvent read FOnEvent write FOnEvent;
property OnEventExt: TMyEventExt read FOnEventExt write FOnEventExt;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyBase }
constructor TMyBase.Create;
begin
FName := 'hehf';
FAge := 99; //不赋值时默认为0
FOnEvent := SetEvent1;
FOnEventExt := SetEventExt1; //这时不能带参数
end;
procedure TMyBase.SetAge(const AValue: Integer);
begin
if (AValue > 0) and (AValue < 130) then
FAge := AValue
else
FAge := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TmpMy: TMyBase;
begin
TmpMy := TMyBase.Create;
ShowMessage(IntToStr(TmpMy.Age)); // 99
TmpMy.Age := 100;
ShowMessage(IntToStr(TmpMy.Age)); // 100
TmpMy.OnEvent; //触发关联事件
TmpMy.Free;
end;
procedure TMyBase.SetEvent1;
begin
ShowMessage('Event 1'
相关文档:
community.csdn.net/Expert/topic/3423/3423580.xml?temp=.7675897
主 题: 怎样用DELPHI接收摄像头的图象
作 者: benbenpear (笨笨)
等 级:
信 誉 值: 100
所属社区: Delphi GAME,图形处理/多媒体
问题点数: 0 ......
一、概述及示例代码
Delphi中包括许多已经封装好的类及控件,其中的非可视化控件库以功能方式划分可处理诸多应用需求。若使用C++实现系统时对某些功能简单调用delphi中现成的库时即可。因此将delphi中的库以DLL形式封装好之后如何将方法导出可供C++调用是本文记录的重点。C++调用的方式有多种,在这里只讨论一种静 ......
名称 类型 说明
--------------------------------------------------------- ......
枚举类型
Pascal程序不仅用于数值处理,还更广泛地用于处理非数值的数据。例如,性别、月份、星期几、颜色、单位名、学历、职业等。
1、枚举类型的定义
格式: type 枚举类型标识符=(标识符1,标识符2,…,标识符n)
2、枚举类型数据特点
① 枚举元素只能是标识符;
例如,下列类型定义是合法的:
type ......
Delphi字符串加密解密函数
功能:字符串加密和解密
首先定义一个常量数组
const
XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47); //字符串加密用
在程序里加入以下两个函数,
function Enc(Str:String):String;//字符加密函數 這是用的一個 ......