Delphi_HELP函数集.doc_第1页
Delphi_HELP函数集.doc_第2页
Delphi_HELP函数集.doc_第3页
Delphi_HELP函数集.doc_第4页
Delphi_HELP函数集.doc_第5页
已阅读5页,还剩142页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

HELP函数集-abs(x)绝对值arctan(x)反正切cos(x)传回馀弦函数值exp(x)e的x次幂frac(x)取小数部分int(x)取整ln(x)自然对数sin(x)传回正弦函数值sqr(x)x*xsqrt(x)平方根其它pred(x)pred(D)=C,pred(true)=1;succ(x)succ(Y)=Z,succ(pred(x)=xord(x)求x在字符集中的序号,如ord(A)=65chr(x)chr(65)=Around(x)四舍五入trunc(x)trunc(4.8)=4,trunc(-3.6)=-3upcase(x)upcase(a)=Ahi(I)hi($2A30)=$2Alo(I)lo($2A30)=$30random(n)产生0,n)间的随机整数sizeof(name)求出某类型或变量在内存中占用的字节数swap(num)swap($3621)=$2136=Arithmeticroutines数学运算=Abs绝对值-UnitSystem函数原型functionAbs(X);说明X为整数or实数.范例varr:Real;i:Integer;beginr:=Abs(-2.3);2.3i:=Abs(-157);157end;-ArcTan三角函数-范例CosvarR:Extended;beginR:=Cos(Pi);end;-Sin-范例varR:Extended;S:string;beginR:=Sin(Pi);Str(R:5:3,S);Canvas.TextOut(10,10,TheSinofPiis+S);end;-UnitSystem函数原型functionArcTan(X:Extended):Extended;函数原型functionCos(X:Extended):Extended;函数原型functionSin(X:Extended):Extended;-说明X为径度.Tan(x)=Sin(x)/Cos(x)ArcSin(x)=ArcTan(x/sqrt(1-sqr(x)ArcCos(x)=ArcTan(sqrt(1-sqr(x)/x)左边这三个不是函数,而是右边运算求得.范例varR:Extended;beginR:=ArcTan(Pi);end;范例varR:Extended;S:string;beginR:=Sin(Pi);Str(R:5:3,S);Canvas.TextOut(10,10,TheSinofPiis+S);end;-Frac求一个实数的小数部份-UnitSystem函数原型functionFrac(X:Real):Real;说明X为实数.范例varR:Real;beginR:=Frac(123.456);0.456R:=Frac(-123.456);-0.456end;-Int求一个实数的整数部份-UnitSystem函数原型functionInt(X:Real):Real;说明X为实数.范例varR:Real;beginR:=Int(123.456);123.0R:=Int(-123.456);-123.0end;-Pi就是数学的Pi-UnitSystem函数原型functionPi:Extended;说明它是一个函数,但我们就把它当作是预设的变数来用吧!Pi=3.1415926535897932385-SqrX的平方-范例varS,Temp:string;beginStr(Sqr(5.0):3:1,Temp);S:=5squaredis+Temp+#13#10;Str(Sqrt(2.0):5:4,Temp);S:=S+Thesquarerootof2is+Temp;MessageDlg(S,mtInformation,mbOk,0);end;-SqrtX的平方根-UnitSystem函数原型functionSqr(X:Extended):Extended;函数原型functionSqrt(X:Extended):Extended;范例varS,Temp:string;beginStr(Sqr(5.0):3:1,Temp);S:=5squaredis+Temp+#13#10;Str(Sqrt(2.0):5:4,Temp);S:=S+Thesquarerootof2is+Temp;MessageDlg(S,mtInformation,mbOk,0);end;-Ln自然对数-范例vare:real;S:string;begine:=Exp(1.0);Str(ln(e):3:2,S);S:=e=+FloatToStr(e)+;ln(e)=+S;Canvas.TextOut(10,10,S);end;-Exp指数-UnitSystem函数原型functionLn(X:Real):Real;函数原型functionExp(X:Real):Real;范例vare:real;S:string;begine:=Exp(1.0);Str(ln(e):3:2,S);S:=ln(e)=+S;Canvas.TextOut(10,10,S);end;-Dateandtimeroutines日期及时间函数-Date传回目前的日期UnitSysUtils函数原型functionDate:TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);beginLabel1.Caption:=Todayis+DateToStr(Date);end;-DateTimeToStr日期时间转换成内定型字串(1996/12/2009:12:20PM)-UnitSysUtils函数原型functionDateTimeToStr(DateTime:TDateTime):string;范例procedureTForm1.Button1Click(Sender:TObject);beginLabel1.Caption:=DateTimeToStr(Now);end;-DateTimeToString日期时间转换成自定型字串-UnitSysUtils函数原型procedureDateTimeToString(varResult:string;constFormat:string;DateTime:TDateTime);范例procedureTForm1.FormCreate(Sender:TObject);vars:string;beginDateTimeToString(s,dddd,mmmmd,yyyyathh:mmAM/PM,Now);Label1.Caption:=s;end;结果星期五,十二月20,1996at09:20PM-*Format格式叁考下面.FormatDateTime.-DateToStr日期转换成内定型字串.(1996/12/20)-UnitSysUtils函数原型functionDateToStr(Date:TDateTime):string;范例procedureTForm1.Button1Click(Sender:TObject);beginLabel1.Caption:=Todayis+DateToStr(Date);end;#Date,DateToStrExample-DayOfWeek求叁数日期是星期几.-UnitSysUtils函数原型functionDayOfWeek(Date:TDateTime):Integer;说明传回值是一整数,17.星期日为1.范例procedureTForm1.Button1Click(Sender:TObject);varADate:TDateTime;days:array1.7ofstring;begindays1:=Sunday;days2:=Monday;days3:=Tuesday;days4:=Wednesday;days5:=Thursday;days6:=Friday;days7:=Saturday;ADate:=StrToDate(Edit1.Text);ShowMessage(Edit1.Text+isa+daysDayOfWeek(ADate);end;#StrToDate,DayOfWeekExample-DecodeDate将TDateTime型态的日期变数,转为Word型态.-范例procedureTForm1.Button1Click(Sender:TObject);varPresent:TDateTime;Year,Month,Day,Hour,Min,Sec,MSec:Word;beginPresent:=Now;DecodeDate(Present,Year,Month,Day);Label1.Caption:=TodayisDay+IntToStr(Day)+ofMonth+IntToStr(Month)+ofYear+IntToStr(Year);DecodeTime(Present,Hour,Min,Sec,MSec);Label2.Caption:=ThetimeisMinute+IntToStr(Min)+ofHour+IntToStr(Hour);end;#DecodeDate,DecodeTimeExample-DecodeTime将TDateTime型态的时间变数,转为Word型态.-UnitSysUtils函数原型procedureDecodeDate(Date:TDateTime;varYear,Month,Day:Word);函数原型procedureDecodeTime(Time:TDateTime;varHour,Min,Sec,MSec:Word);范例procedureTForm1.Button1Click(Sender:TObject);varPresent:TDateTime;Year,Month,Day,Hour,Min,Sec,MSec:Word;beginPresent:=Now;DecodeDate(Present,Year,Month,Day);Label1.Caption:=TodayisDay+IntToStr(Day)+ofMonth+IntToStr(Month)+ofYear+IntToStr(Year);DecodeTime(Present,Hour,Min,Sec,MSec);Label2.Caption:=ThetimeisMinute+IntToStr(Min)+ofHour+IntToStr(Hour);end;-EncodeDate将Word型态的日期变数,转为TDateTime型态.-范例procedureTForm1.Button1Click(Sender:TObject);varMyDate:TDateTime;beginMyDate:=EncodeDate(StrToInt(Edit1.Text),StrToInt(Edit2.Text),StrToInt(Edit3.Text);Label1.Caption:=DateToStr(MyDate);end;-EncodeTime将Word型态的时间变数,转为TDateTime型态.-UnitSysUtils函数原型functionEncodeDate(Year,Month,Day:Word):TDateTime;函数原型functionEncodeTime(Hour,Min,Sec,MSec:Word):TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);varMyDate:TDateTime;MyTime:TDateTime;beginMyDate:=EncodeDate(83,12,31);Label1.Caption:=DateToStr(MyDate);MyTime:=EncodeTime(0,45,45,7);Label2.Caption:=TimeToStr(MyTime);end;范例procedureTForm1.Button1Click(Sender:TObject);varMyTime:TDateTime;beginMyTime:=EncodeTime(0,45,45,7);Label1.Caption:=TimeToStr(MyTime);end;-FormatDateTime将日期时间依Format的格式转换给一字串.-UnitSysUtils函数原型functionFormatDateTime(constFormat:string;DateTime:TDateTime):string;*类似DateTimeToString.Format格式c内定值ShortDateFormat的格式.(1996/12/2009:20:15PM).d日期,前面不补0.(1-31)dd日期,前面补0.(01-31)ddd星期.(星期日).Dddd中文2.01版,同上.ddddd日期.(1996/12/20)dddddd日期.(1996年12月20日)m月份,前面不补0.(1-12)mm月份,前面补0.(01-12)mmm中文显示.(十二月)mmmm中文2.01版,同上.Yy年度.(00-99)yyyy年度.(0000-9999)h小时.(0-23)hh小时.(00-23)n分钟.(0-59)nn分钟.(00-59)s秒钟.(0-59)ss秒钟.(00-59)t时间.(09:20PM)tt时间.(09:20:15PM)am/pm单独显示amorpm.(若大写,则显示大写)a/p单独显示aorp.范例ThefollowingexampleassignsThemeetingisonWednesday,February15,1995at10:30AMtothestringvariableS.S:=FormatDateTime(Themeetingisondddd,mmmmd,yyyy,athh:mmAM/PM,StrToDateTime(2/15/9510:30am);/?-Now传回目前的日期时间.-UnitSysUtils函数原型functionNow:TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);beginLabel1.Caption:=DateTimeToStr(Now);end;#Now,DateTimeToStrExample-StrToDate将字串转为TDateTime型态的日期.-UnitSysUtils函数原型functionStrToDate(constS:string):TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);varADate:TDateTime;beginADate:=StrToDate(Edit1.Text);Label1.Caption:=DateToStr(ADate);end;范例procedureTForm1.Button1Click(Sender:TObject);varADate:TDateTime;days:array1.7ofstring;begindays1:=Sunday;days2:=Monday;days3:=Tuesday;days4:=Wednesday;days5:=Thursday;days6:=Friday;days7:=Saturday;ADate:=StrToDate(Edit1.Text);ShowMessage(Edit1.Text+isa+daysDayOfWeek(ADate);end;#StrToDate,DayOfWeekExample-StrToDateTime将字串转为TDateTime型态的日期时间.-UnitSysUtils函数原型functionStrToDateTime(constS:string):TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);varADateAndTime:TDateTime;beginADateAndTime:=StrToDateTime(Edit1.Text);Table1.FieldByName(TimeStamp).AsDateTime:=ADateAndTime;end;-StrToTime将字串转为TDateTime型态的时间.-UnitSysUtils函数原型functionStrToTime(constS:string):TDateTime;范例procedureTForm1.Button1Click(Sender:TObject);varATime:TDateTime;beginATime:=StrToTime(Edit1.Text);ifATime0.50thenShowMessage(GoodMorning)elseShowMessage(GoodAfternoon);end;-Time传回目前的时间.-UnitSysUtils函数原型functionTime:TDateTime;范例procedureTForm1.Timer1Timer(Sender:TObject);varDateTime:TDateTime;str:string;beginDateTime:=Time;/storethecurrentdateandtimestr:=TimeToStr(DateTime);/convertthetimeintoastringCaption:=str;/displaythetimeontheformscaptionNoteThiscouldhavebeendonewiththefollowinglineofcode:Caption:=TimeToStr(Time);end;#Time,TimeToStrExample-TimeToStr时间转换成内定型字串.(09:20:15PM)-UnitSysUtils函数原型functionTimeToStr(Time:TDateTime):string;GetMemprocedure配置记忆体程序New配置指位器P的记忆体空间,大小为P所指型态的大小.-Dispose释放New所配置的记忆体.-UnitSystem函数原型procedureNew(varP:Pointer);函数原型procedureDispose(varP:Pointer);范例typePListEntry=TListEntry;TListEntry=recordNext:PListEntry;Text:string;Count:Integer;end;varList,P:PListEntry;begin.New(P);P.Next:=List;P.Text:=Helloworld;P.Count:=1;List:=P;.Dispose(P);end;范例typeStr18=string18;varP:Str18;beginNew(P);P:=Nowyouseeit.;Dispose(P);Nowyoudont.end;-GetMem配置指位器P的记忆体空间,大小可自行设定.-范例varF:file;Size:Integer;Buffer:PChar;beginAssignFile(F,test.txt);Reset(F,1);trySize:=FileSize(F);GetMem(Buffer,Size);tryBlockRead(F,Buffer,Size);ProcessFile(Buffer,Size);finallyFreeMem(Buffer);end;finallyCloseFile(F);end;end;-FreeMem释放GetMem所配置的记忆体.-UnitSystem函数原型procedureGetMem(varP:Pointer;Size:Integer);函数原型procedureFreeMem(varP:Pointer;Size:Integer);范例varF:file;Size:Integer;Buffer:PChar;beginAssignFile(F,test.txt);Reset(F,1);trySize:=FileSize(F);GetMem(Buffer,Size);tryBlockRead(F,Buffer,Size);ProcessFile(Buffer,Size);finallyFreeMem(Buffer);end;finallyCloseFile(F);end;end;=File-managementroutines档案管理常式=-ChangeFileExt变更档案的副档名-UnitSysUtils函数原型functionChangeFileExt(constFileName,Extension:string):string;范例procedureTForm1.Button1Click(Sender:TObject);varS:String;P1:String;P2:String;beginP1:=abc.txt;P2:=.ini;S:=ChangeFileExt(P1,P2);Label1.Caption:=S;end;结果S=abc.iniP1:=abcP2:=.iniS=abc.iniP1:=c:windowsabc.txtP2:=.iniS=c:windowsabc.iniP1:=abc.txtP2:=iniS=abcini*注意:P2的第一位元必须有一点.ini范例procedureTForm1.ConvertIcon2BitmapClick(Sender:TObject);vars:string;Icon:TIcon;beginOpenDialog1.DefaultExt:=.ICO;OpenDialog1.Filter:=icons(*.ico)|*.ICO;OpenDialog1.Options:=ofOverwritePrompt,ofFileMustExist,ofHideReadOnly;ifOpenDialog1.ExecutethenbeginIcon:=TIcon.Create;tryIcon.Loadfromfile(OpenDialog1.FileName);s:=ChangeFileExt(OpenDialog1.FileName,.BMP);Image1.Width:=Icon.Width;Image1.Height:=Icon.Height;Image1.Canvas.Draw(0,0,Icon);Image1.Picture.SaveToFile(s);ShowMessage(OpenDialog1.FileName+Savedto+s);finallyIcon.Free;end;end;end;#SaveToFile,Create,Height,Width,Canvas,ChangeFileExtexample-ExpandFileName将档案名称加在目前所在之路径全名之後-UnitSysUtils函数原型functionExpandFileName(constFileName:string):string;说明设目前目录为c:windows档案名称为abc.txt则结果为c:windowsabc.txt*此函数并不是求abc.txt的所在路径.范例procedureTForm1.Button1Click(Sender:TObject);varS:String;beginS:=ExpandFileName(abc.txt);Label1.Caption:=S;end;范例procedureTForm1.Button1Click(Sender:TObject)beginListBox1.Items.Add(ExpandFileName(Edit1.Text);end;-DirectoryExists目录是否存在-UnitFileCtrlusesFileCtrl;procedureTForm1.Button1Click(Sender:TObject);beginifnotDirectoryExists(c:temp)thenifnotCreateDir(C:temp)thenraiseException.Create(Cannotcreatec:temp);end;-ForceDirectories目录-UnitFileCtrl函数原型functionForceDirectories(Dir:string):Boolean;procedureTForm1.Button1Click(Sender:TObject);varDir:string;beginDir:=C:APPSSALESLOCAL;ifDirectoryExists(Dir)thenLabel1.Caption:=Dir+wascreatedend;-ExpandUNCFileName同上(只是得到网路上的路径)-UnitSysUtils函数原型functionExpandUNCFileName(constFileName:string):string;ExtractFileDir分析字串中的路径UnitSysUtils函数原型functionExtractFileDir(constFileName:string):string;说明设S字串为c:windowsabc.txt则结果为c:windows*功能在於由任何部份传来的叁数,加以分析它的路径范例procedureTForm1.Button1Click(Sender:TObject);varS:String;P1:String;beginP1:=c:windowsabc.txt;S:=ExtractFileDir(P1);Label1.Caption:=S;end;S=c:windowsP1:=abc.txtS=P1:=c:abc.txtS=c:P1:=c:abc.txtS=c:-ExtractFileDrive分析字串中的磁碟机名称-UnitSysUtils函数原型functionExtractFileDrive(constFileName:string):string;*功能同上,只是传回磁碟机名称.范例procedureTForm1.Button1Click(Sender:TObject);varS:String;P1:String;beginP1:=c:windowsabc.txt;S:=ExtractFileDrive(P1);Label1.Caption:=S;end;S:=c:P1:=abc.txtS=-ExtractFileExt分析字串中的档案名称的副档名-UnitSysUtils函数原型functionExtractFileExt(constFileName:string):string;范例procedureTForm1.Button1Click(Sender:TObject);varS:String;P1:String;beginP1:=c:windowsabc.txt;S:=ExtractFileExt(P1);Label1.Caption:=S;end;S=.txtP1:=c:windowsabcS=范例MyFilesExtension:=ExtractFileExt(MyFileName);-ExtractFileName分析字串中的档案名称(只传回档案名称)-UnitSysUtils函数原型functionExtractFileName(constFileName:string):string;范例procedureTForm1.Button1Click(Sender:TObject);varS:String;P1:String;beginP1:=c:windowsabc.txt;S:=ExtractFileName(P1);Label1.Caption:=S;end;S=abc.txt范例procedureTForm1.Button1Click(Sender:TObject);varBackupName:string;FileHandle:Integer;StringLen:Integer;X:Integer;Y:Integer;beginifSaveDialog1.ExecutethenbeginifFileExists(SaveDialog1.FileName)thenbeginBackupName:=ExtractFileName(SaveDialog1.FileName);BackupName:=ChangeFileExt(BackupName,.BAK);ifnotRenameFile(SaveDialog1.FileName,BackupName)thenraiseException.Create(Unabletocreatebackupfile.);end;FileHandle:=FileCreate(SaveDialog1.FileName);Writeoutthenumberofrowsandcolumnsinthegrid.FileWrite(FileHandle,StringGrid1.ColCount,SizeOf(StringGrid1.ColCount);FileWrite(FileHandle,StringGrid1.RowCount,SizeOf(StringGrid1.RowCount);forX:=0toStringGrid1.ColCount?1dobeginforY:=0toStringGrid1.RowCount?1dobeginWriteoutthelengthofeachstring,followedbythestringitself.StringLen:=Length(StringGrid1.CellsX,Y);FileWrite(FileHandle,StringLen,SizeOf(StringLen);FileWrite(FileHandle,StringGrid1.CellsX,Y,Length(StringGrid1.CellsX,Y);end;end;FileClose(FileHandle);end;end;#FileExists,RenameFile,FileCreate,FileWrite,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论