Delphi笔记(一些比较少用的知识)
1、随机函数
一般是用Random函数,并在之前用Randomize初始化,原来还有:
RandomFrom 从参数指定的数组中随机选出一个数值(整数、字符串等)
例:RandomFrom(['D1','D2','D3','D4'])
RandomRange 在整数范围随机产生一个整数。
例:X:=RandomRange(20,50);// 20<=X<=50 X为整数
2、时间函数
FormatDateTime 格式化字符串
例:FormatDateTime('yyyy年 mm月 dd日 hh时 nn分 ss秒',now())
DecodeDate 将日期分解为年月日
例:DecodeDate(now(),Year,Month,Day)//Year,Month,Day:word
同理还有 DecodeTime(now(),hour,minute,second,msecond)
反函数是 EncodeDate(Year,Month,Day:word):TDateTime;
EncodeTime(hour,minute,second,msecond:word):TDateTime;
3、在循环中用到的中断命令
Abort 无记录异常
Break 中断循环
Continue 跳到下一循环
Exit 跳出函数过程
RunError 中止程序
Halt 中止程序,返回操作系统
4、其他函数
Odd 判断奇数偶数
Pred 前一序号的值
Succ 后一序号的值
5、类的属性
属性的索引
function GetX(Const Index:Integer):Integer;
Procedure SetX(Const Index,Value:Integer);
property A:integer index(0) read GetX write SetX;
property B:integer index(1) read GetX write SetX;
A,B共同使用同一个函数和过程
数组属性
function GetX(Index:Integer):String;
Procedure SetX(Index:Integer,Const Value:String);
property X[index:integer]:String read GetX write SetX;
6、类运算符号
= 两个类是否相等
例:if Edit1.ClassType = Edit2.ClassType then...
<> 两个类是否不相等
is 一个对象是否一个类(或其子类)的实例
as 将类对象转换成为自身类或父类
评论