delphi type
声明:
1. type Name = Existing type;
2. type Name = type Existing type;
3. type Name = (EnumValue1 [=value], EnumValue2 [=value] ...);
4. type Name = Expression1..Expression2;
5. type Name = ^Existing type;
6. type Name = array[...] of Existing type;
7. type Name = class ... end;
8. type Name = class of Existing class
9. type Name = dispinterface ... end;
10. type Name = file of Existing type;
11. type Name = function ...;
12. type Name = interface ... end;
13. type Name = object ... end;
14. type Name = procedure ...;
15. type Name = record ... end;
16. type Name = set of Ordinal values
描述:Type关键词是Delphi的基础部分,不像其它语言,它允许创建变量和过程的新类型(种类)。这些新的类型可以被引用,就像它是语言的一部分一样。
比如:Type TCourtCards = (Ace,Jack,Queen,King);
允许定义一个这种“type”的新变量:var Card:TCourtCard; Card:=Queen;
一般都在类型名字的前缀加“T”,这是一种有用的约定。
1.type Name = Existing type
参考一个现有的类型,比如用新的名字来替代string。
2.type Name = type Existing type
这个与上面的效果一样,但是它确保在运行时,这个类型的变量被识别为它的新类型名称,而不是原先已存在的类型名称。
3.type Name = (EnumValue1,EnumValue2…)
定义一个枚举类型,包含了值EnumValue1,EnumValue2等等。它是用户自定义的名字,列举出所有有可能的值。这些值在你的程序中必 须是唯一的,一旦在类型中定义了它,只可通过两种方法引用:指定或引用一个这种类型的变量;和用Ord关键词取得序数作为数字值。见例子。
注:这些枚举元素在定义的时候,它的位置值为0,1,2,等等,除非这个值用“=value”覆写。如:
Type Days = (Monday = 1,Tuesday,Wed…);
这里,Monday位置值被设为1,Tuesday为2,Wednesday 为3,依次类推。
4.Type Name = Expression1..Expression2
这里是一个完整的整数或字符范围,从Expression1表达式到Expression2表达式。表达式1和2可以是计算结结果为整数或字符的公式,或仅是整数或字符常量。如:Type TAlphabet =’A’..’z';通常用于定义字符范围,从大写A到小写z。
5.type Name = ^Existing type
‘^’符号是指向现有类型的指针。它经常用于导航记录Record类型。
6.type Name = array[…] of existing type
一个结构类型,用一个新的类型封装了某类型的数组。
7.type Name = class…end
用于定义一个新类的结构,详见Class关键词。
8.type Name = class of existing class
提供一个meta-class定义,详见Class关键词。
9.type Name = dispinterface … end
一个分派接口(dispatch interface)类型,详见Dispinterface关键词。
10.type Name = file of Existing type
定义一个指向文件的类型,这个文件包含了给定类型的记录。(默认地,文件包含二进制数据)
11.type Name = function …
定义一个函数当作类型,允许这个函数被定义作为参数用于子程序。
12.type Name = interface … end
用于定义接口的结构。详见Interface关键词。
13.type Name = object … end
相当于类定义,已过时淘汰。
14.type Name = procedure …
定义一个过程当作类型,允许这个过程被定义作为参数用于子程序。
15.type Name = record … end
定义记录类型,在给定的名称下封装数据结构。详见Record关键词。
16.type Name = set of Ordinal values
定义有序数的子界。定义了一个整数或字符的范围。详见Set关键词。
{举一些type例子}
Type
TString1 = string; // 1. type Name = Existing type
TString2 = type string; // 2. type Name = type Existing type
TTemp = (Hot, Warm, Cold); // 3. type Name = (Enum1, Enum2 ...)
TExpr = 5*2 .. 6*3; // 4. type Name = Expr1 .. Expr2
// 5. See the Pointer keyword
TArray = array[1..3] of byte; //6. type Name = array[...] of type
// 7. 见TFrom1类定义
// 8. 详见 Class 关键词
// 9. 详见 Dispinterface 关键词
// 10. 详见 File 关键词
// 11. 详见 Function 关键词
// 12. 详见 Interface 关键词
// 13. 淘汰不用了
// 14. 详见 Procedure 关键词
TRecord = record // 15. type Name = record .. end;
header : string;
value : Integer;
end;
TLetters = set of 'A'..'z'; // 16. type Name = set of Ordinals
var
// 用上面的类型定义变量
firstName : TString1;
lastName : TString2;
temperature : TTemp;
expression : TExpr;
myArray : TArray;
myRecord : TRecord;
letters : TLetters;
begin
// 为变量赋值
firstName := 'Neil';
lastName := 'Moffatt';
temperature := Cold;
expression := 10;
myArray[1] := 5;
myRecord.header := 'data file';
letters := ['F'..'Q'];
end;
delphi type的更多相关文章
- Delphi与各数据库数据类型比较
Delphi数据类型与各数据库数据类型对比如下表,如有具体说明见表中脚注: Delphi Type Oracle Types SQL Server Types MySQL Types [1] Inte ...
- Delphi 二维码产生和扫描
Zint用于产生二维码. Zxing用读取二维码. VFrames.pas和VSample.pas用于摄像头. 另附带摄像头相关的类库,也可用开源的dspack也可用于摄像头的需求. 以上为开源的信息 ...
- Delphi 与 C/C++ 数据类型对照表(最新的tokyo)
更新,下面这table为最新的tokyo基本数据类型与C++的对照关系: Delphi to C++ types mapping Go Up to Support for Delphi Data ...
- XE4 TStringDynArray 比 c6 的TStringList 好用 字符串 分解 分割 转换 TByteDynArray
TStringDynArray 动态数组 字符串 分解 分割 System::DynamicArray<System::UnicodeString> TByteDynArray, ...
- 利用Delphi的File Of Type创建并管理属于你自己的数据库
http://www.360doc.com/content/16/1128/19/28222077_610249962.shtml 利用Delphi的File Of Type创建并管理属于你自己的数据 ...
- Delphi Data Type to C# Data Type
Delphi DataType C# datatype ansistring string boolean bool byte byte char char comp double currency ...
- delphi 如何关闭 Unsafe typecast of 和 Unsafe type 的waring
有时在Delphi使用指针类型的数据,总是提示如下: [Warning] FGroupFeedBack.pas(796): Unsafe typecast of 'Pointer' to 'TObje ...
- Where is the ActiveX Project Type for Delphi 10.1 Berlin
n 10.1 Berlin the ActiveX project types are missing from the New Items Window under Delphi. They are ...
- delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决
delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...
随机推荐
- python 打印 str 字符串的实际内容 repr(str)
python 打印 str 字符串的实际内容 repr(str) s = 'aa' print(repr(s))
- JAVA实现WEBSERVICE 上传下载
因公司新项目决定使用webservice与其它项目做交互,于是开始了webservice之旅. 初入webservice的时候第一个接触的工具叫axis2,网上有着大量的简单案例.功能很强大,代 ...
- Git 的核心概念
本文不是Git使用教学篇,而是偏向理论方面,旨在更加深刻的理解Git,这样才能更好的使用它,让工具成为我们得力的助手. 版本控制系统 Git 是目前世界上最优秀的分布式版本控制系统.版本控制系统是能够 ...
- 富文本编辑器直接从 word 中复制粘贴公式
在之前在工作中遇到在富文本编辑器中粘贴图片不能展示的问题,于是各种网上扒拉,终于找到解决方案,在这里感谢一下知乎中众大神以及TheViper. 通过知乎提供的思路找到粘贴的原理,通过TheViper找 ...
- Codevs 2492 上帝造题的七分钟 2(线段树)
时间限制: 1 s 空间限制: 64000 KB 题目等级 : 大师 Master 题目描述 Description XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. " ...
- Win内核原理与实现学习笔记3-windows系统结构
1.概述 1.1windows采用了双模式(dual mode)结构来保护操作系统本身,以避免被应用程序的错误而波及.操作系统核心运行在内核模式(kernel mode)下,应用程序的代码运行在用户模 ...
- P1106 删数问题 自己码风好菜
一个人的码风好坏究竟会影响多少
- c++ 实现等待5s
#include <stdio.h> /* puts, printf */ #include <time.h> /* time_t, struct tm, time, loca ...
- html5获取地理位置和定位
1.H5地理位置定位功能 首先判断用户浏览器是否支持该功能,目前大多数现代浏览器均支持,获取位置信息需用户授权同意 function getLocation(){ if (navigator.geol ...
- Linux设备驱动 之 中断处理程序
注册中断处理程序 中断处理程序是管理硬件驱动程序的组成部分:如果设备使用中断,那么相应的驱动程序就注册一个中断处理程序: 驱动程序通过request_irq()函数注册,并且激活给定的中断线,以处理中 ...