学习结构[记录]类型(7) - 结构也可以有构造函数
2008-01-09 16:59
288 查看
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} type TRec = record {定义结构 TRec} name: ShortString; age: Word; constructor Create(str: ShortString; w: Word); {构造函数} end; { TRec 构造函数实现} constructor TRec.Create(str: ShortString; w: Word); begin name := str; age := w; end; //使用结构 procedure TForm1.Button1Click(Sender: TObject); var rec: TRec; begin rec.Create('李四', 81); ShowMessage(rec.name); {李四} end; end.
结构的方法、属性都是在 Delphi 7 以后的版本中加入的, 非常类似与"类", 但又不如在"类"里完善;
它的其他一些新特性也好像是从"类"里搬过来的, 等在"类"里面研究吧.
相关文章推荐
- 学习结构[记录]类型(3) - 结构间的关系
- 学习结构[记录]类型(2) - 压缩结构
- 学习结构[记录]类型(4) - 结构指针
- 学习结构[记录]类型(6) - 结构的属性
- 学习结构[记录]类型(8) - 结构嵌套
- c#的结构类型也可以有构造函数
- 学习结构[记录]类型(9) - 变体结构
- 学习结构[记录]类型(4) - 结构指针
- C++中struct也有构造函数与析构函数,也可以有访问类型控制以及结构体大小,类大小
- Delphi中学习结构[记录]类型用法(转载)
- 学习结构[记录]类型(1) - 开始
- C++中struct也有构造函数与析构函数,也可以有访问类型控制以及结构体大小,类大小
- 学习结构[记录]类型(2) - 压缩结构
- 学习结构[记录]类型(5) - 结构的方法
- 学习结构[记录]类型(3) - 结构间的关系
- c#的结构类型也可以有构造函数
- Kotlin学习记录(二)—— Kotlin的变量、属性、类、构造函数、继承、方法
- linux学习(五)系统目录结构,ls命令,文件类型,alias
- multiset基础学习,可以有重复类型的多重集合容器
- C# 2010 从入门到精通 学习笔记8 第9章 使用枚举和结构来创建值类型