打印本文 打印本文 关闭窗口 关闭窗口
DELPHI常用函数集及简要范例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数19874  更新时间:2009/4/23 18:30:33  文章录入:mintao  责任编辑:mintao
   procedure TForm1.AgainClick(Sender: TObject);
   begin
     FindNext(SRec);
     Label1.Caption := SRec.Name + '''' is '''' + IntToStr(SRec.Size) + 
    '''' bytes in size'''';
   end;
   procedure TForm1.FormClose(Sender: TObject);
   begin
     FindClose(SRec);
   end

   TSearchRec = record
    Time: Integer;
    Size: Integer;
    Attr: Integer;
    Name: TFileName;
    xcludeAttr: Integer;
    FindHandle: THandle;
    FindData: TWin32FindData;
   end;

============================================
Floating-point conversion routines 浮点数转换函式
============================================
FloatToDecimal 将浮点数转换为十进位数.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 procedure FloatToDecimal(var Result: TFloatRec; const Value;
    ValueType: TFloatValue; Precision, Decimals: Integer);
-----------------------------------------------------------------------------
FloatToStrF  将浮点数转换为格式化字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function FloatToStrF(Value: Extended; Format: TFloatFormat; 
    Precision,Digits: Integer): string;
-----------------------------------------------------------------------------
FloatToStr   将浮点数转换为字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function FloatToStr(Value: Extended): string;
-----------------------------------------------------------------------------
FloatToText  将浮点数转换为格式化十进位.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function FloatToText(Buffer: PChar; const Value; ValueType: 
    TFloatValue;Format: TFloatFormat; Precision, Digits: 
    Integer): Integer;
-----------------------------------------------------------------------------
FloatToTextFmt 将浮点数转换为格式化十进位.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function FloatToTextFmt(Buffer: PChar; const Value; 
    ValueType: TFloatValue; Format: PChar): Integer;
-----------------------------------------------------------------------------
FormatFloat  将浮点数转换为格式化字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function FormatFloat(const Format: string; Value: Extended): 
    string;
-----------------------------------------------------------------------------
StrToFloat   将字串转换为浮点数.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrToFloat(const S: string): Extended;
范例  procedure TForm1.Button1Click(Sender: TObject);
   var
     Value:Double;
     S:String;
   begin
     S:='''' 1234.56  '''';
     Value:=StrToFloat(S);
     Label1.Caption:=Format(''''转换为 [%9.3f]'''',[Value]);
   end;

注意  若S字串含有非数字字元,会产生错误讯号.
-----------------------------------------------------------------------------
TextToFloat  将 null-terminated 字串转换为浮点数.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function TextToFloat(Buffer: PChar; var Value; ValueType: 
    TFloatValue): Boolean;

===========================================
 Flow-control routines 流程控制常式
===========================================
Break    从 for, while, or repeat 终止跳出.
-----------------------------------------------------------------------------
Unit  System
函数原型  procedure Break;
范例  var
     S: string;
   begin
     while True do
    begin
     ReadLn(S);
     try
      if S = '''' then Break;
      WriteLn(S);
     finally
      { do something for all cases }
     end;
    end;
   end;
-----------------------------------------------------------------------------
Continue   从 for, while, or repeat 继续执行.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Continue;
范例  var
     F: File;
     i: integer;
   begin
     for i := 0 to (FileListBox1.Items.Count - 1) do
    begin
     try
      if FileListBox1.Selected[i] then
       begin
     if not FileExists(FileListBox1.Items.Strings[i]) then
      begin
      MessageDlg(''''File: '''' +FileListBox1.Items.Strings[i] 
      + '''' not found'''', mtError, [mbOk], 0);
      Continue;
      end;
       AssignFile(F, FileListBox1.Items.Strings[i]);
       Reset(F, 1);
       ListBox1.Items.Add(IntToStr(FileSize(F)));
       CloseFile(F);
       end;
     finally
       { do something here }
     end;
    end;
   end;
范例
var
  F: File;
  i: Integer;
begin
  for i := 0 to (FileListBox1.Items.Count - 1) do begin
  try
    if FileListBox1.Selected[i] then 
    begin
      if not FileExists(FileListBox1.Items.Strings[i]) then begin
        MessageDlg(''''File: '''' + FileListBox1.Items.Strings[i] + 
                   '''' not found'''', mtError, [mbOk], 0);
        Continue;
      end;
      AssignFile(F, FileListBox1.Items.Strings[i]);

      Reset(F, 1);
      ListBox1.Items.Add(IntToStr(FileSize(F)));
      CloseFile(F);
    end;
   finally
   { do something here }
   end;
  end;
end;
## Continue, Items, Selected Example
-----------------------------------------------------------------------------
Exit    直接离开一个程序.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Exit;
-----------------------------------------------------------------------------
Halt    结束程式返回作业系统.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Halt [ ( Exitcode: Integer) ];
范例  begin
     if 1 = 1 then
    begin
     if 2 = 2 then
       begin
      if 3 = 3 then
        begin
       Halt(1); { Halt right 

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ...  下一页 >> 

打印本文 打印本文 关闭窗口 关闭窗口