理解 Delphi 的类(八) - 关于类的定义
摘要://标准语法 TMyClass1 = class(TObject) end; //如果是继承自 TObject 可以省略 TMyClass2 = class end; //可以实现多个接口; 实现接口时经常用到 TInterfacedObject 类, 它实现了接口的默认方法 TMyClass3 = class(TInterfacedObject, I...
阅读全文
posted @
2008-01-14 13:05
万一
阅读(12079)
推荐(0)
关于类的入门例子(9): 获取对象的 RTTI 属性与事件的函数
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, xmldom, XMLIntf, XMLBrokr, msxmldom, XMLDoc; type TForm1 = class(TFor...
阅读全文
posted @
2008-01-14 02:25
万一
阅读(6271)
推荐(0)
关于类的入门例子(8): 遍历窗体中所有控件的函数
摘要://显示窗体中所有控件的函数 function GetCtrls(Control: TWinControl; List: TStringList): Boolean; var i: Integer; obj: TWinControl; begin for i := 0 to Control.ControlCount-1 do begin obj := TWinContro...
阅读全文
posted @
2008-01-13 21:04
万一
阅读(6103)
推荐(0)
关于类的入门例子(7): 遍历窗体的所有父类
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton...
阅读全文
posted @
2008-01-11 16:43
万一
阅读(4324)
推荐(0)
理解 Delphi 的类(七) - 认识类的多态
摘要:什么是多态? 我的理解就是: 同样一个方法, 在不同的对象里会有不同的实现, 仅此而已. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TFor...
阅读全文
posted @
2008-01-11 02:27
万一
阅读(6018)
推荐(0)
理解 Delphi 的类(六) - 认识类的封装
摘要://这个类中的两个字段没有封装 TMyClass1 = class FName: string; FAge: Integer; end; //这个类中的两个字段封装了, 外部不能读写 TMyClass2 = class private FName: string; FAge: Integer; //public e...
阅读全文
posted @
2008-01-11 02:26
万一
阅读(6464)
推荐(0)
理解 Delphi 的类(五) - 认识类的继承
摘要:先新建一个 VCL Forms Application 工程, 代码中就已经出现了两个类: 一个是 TForm 类; 一个是 TForm1 类; TForm1 继承于 TForm. TForm 是 TForm1 的父类; TForm1 是 TForm 的子类. unit Unit1; interface uses Windows, Messages, SysUtils, Variant...
阅读全文
posted @
2008-01-11 02:25
万一
阅读(7639)
推荐(0)
理解 Delphi 的类(四) - 初识类的事件
摘要:先勾画一下思路: 1、建立一个类, 里面有年龄字段 FAge; 2、通过 Age 属性读写 FAge; 3、如果输入的年龄刚好是 100 岁, 将会激发一个事件, 这个事件我们给它命名为: OnHundred unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Cont...
阅读全文
posted @
2008-01-11 02:24
万一
阅读(8889)
推荐(0)
理解 Delphi 的类(三) - 初识类的属性
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button...
阅读全文
posted @
2008-01-11 02:22
万一
阅读(7909)
推荐(1)
理解 Delphi 的类(二) - 初识类的方法
摘要:说到"类", 就会提到: 属性、方法、事件 (这是类包含的内容); 封装、继承、多态 (这是类的主要用途). 下面定义并调用了了一个过程 MyProc、一个函数 MyFun. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
阅读全文
posted @
2008-01-11 01:23
万一
阅读(7406)
推荐(2)
理解 Delphi 的类(一) - 从结构谈起
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button...
阅读全文
posted @
2008-01-11 00:39
万一
阅读(13055)
推荐(0)
关于类的入门的例子(6): 类引用示例
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; ...
阅读全文
posted @
2007-12-17 16:38
万一
阅读(3912)
推荐(0)
关于类的入门的例子(5): override
摘要:unit Unit1; interface uses Classes, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; TBase = class ...
阅读全文
posted @
2007-12-17 13:43
万一
阅读(4502)
推荐(0)
关于类的入门例子(4): property
摘要://类单元 unit Person; interface type TPerson = class(TObject) private FName: string; FAge: Integer; public procedure SetName(const strName: string); procedure SetAge(const intAge...
阅读全文
posted @
2007-12-13 15:30
万一
阅读(4212)
推荐(0)
关于类的入门例子(3): Create 与 Destroy
摘要://类单元 unit Person; interface uses Dialogs; type TPerson = class(TObject) private FName: string; FAge: Integer; public constructor Create(strName: string; intAge: Integer); d...
阅读全文
posted @
2007-12-13 15:15
万一
阅读(5549)
推荐(0)
关于类的入门例子(2): 数字盒子
摘要://类单元 unit NumBox; interface type TNumBox = class private FCount: Integer; public procedure AddOne; procedure AddFive; procedure ZeroCount; function GetCount: Integer; e...
阅读全文
posted @
2007-12-13 13:56
万一
阅读(4118)
推荐(0)
关于类的入门例子(1): 继承窗体
摘要:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton...
阅读全文
posted @
2007-12-13 12:54
万一
阅读(5846)
推荐(0)
属性的自动完成
摘要://在 type 区写入: TMyClass = class property s: string; end; //然后把光标放在其中,执行 Ctrl+Shift+C,可以自动生成以下代码: TMyClass = class private Fs: string; procedure Sets(const Value: string); publi...
阅读全文
posted @
2007-12-07 14:13
万一
阅读(4642)
推荐(0)
参数默认值
摘要://带默认值的参数只能在后面 function MyFun(a:Integer; b:Integer=1; c:Integer=2): Integer; begin Result := a + b + c; end; procedure TForm1.Button1Click(Sender: TObject); var x: Integer; begin x := MyFun(1)...
阅读全文
posted @
2007-12-06 17:23
万一
阅读(4806)
推荐(0)