打印本文 打印本文 关闭窗口 关闭窗口
DELPHI常用函数集及简要范例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数19885  更新时间:2009/4/23 18:30:33  文章录入:mintao  责任编辑:mintao
bsp;     ftSmallInt:
        IBQuery1.Params[I].AsSmallInt := StrToIntDef(ListItem, 0);
      ftInteger:
        IBQuery1.Params[I].AsInteger := StrToIntDef(ListItem, 0);
      ftWord:

        IBQuery1.Params[I].AsWord := StrToIntDef(ListItem, 0);
      ftBoolean:
        begin
          if ListItem = ''''True'''' then
            IBQuery1.Params[I].AsBoolean := True
          else
            IBQuery1.Params[I].AsBoolean := False;
        end;
      ftFloat:
        IBQuery1.Params[I].AsFloat := StrToFloat(ListItem);
      ftCurrency:
        IBQuery1.Params[I].AsCurrency := StrToFloat(ListItem);
      ftBCD:

        IBQuery1.Params[I].AsBCD := StrToCurr(ListItem);
      ftDate:
        IBQuery1.Params[I].AsDate := StrToDate(ListItem);
      ftTime:
        IBQuery1.Params[I].AsTime := StrToTime(ListItem);
      ftDateTime:
        IBQuery1.Params[I].AsDateTime := StrToDateTime(ListItem);
    end;
  end;
end;
##ParamCount, DataType, StrToIntDef, AsXXX Example
-----------------------------------------------------------------------------
ParamStr  
-----------------------------------------------------------------------------
Unit  System
函数原型 function ParamStr(Index: Integer): string;
说明  ParamStr(0);传回执行档的名称及完整目录.
   (C:\ZIP\ARJ.EXE)
范例
var 
  I: Word;
  Y: Integer;
begin
  Y := 10;
  for I := 1 to ParamCount do
  begin
    Canvas.TextOut(5, Y, ParamStr(I));
    Y := Y + Canvas.TextHeight(ParamStr(I)) + 5;
  end;
end;

Example
procedure TForm1.FormCreate(Sender: TObject);

var
  i: Integer;
  for i := 0 to ParamCount -1 do
  begin
    if LowerCase(ParamStr(i)) = ''''beep'''' then
      Windows.Beep(10000,1000)
    else 
      if (LowerCase(ParamStr(i)) = ''''exit'''' then
      Application.Terminate;
  end;
end;
##ParamCount, ParamStr Example
-----------------------------------------------------------------------------
Random   乱数
-----------------------------------------------------------------------------
Unit  System
函数原型 function Random [ ( Range: Integer) ];
说明  0<=X<Range
范例  var
     I: Integer;
   begin
     Randomize;
     for I := 1 to 50 do
    begin
      { Write to window at random locations }
      Canvas.TextOut(Random(Width), Random(Height), 
     ''''Boo!'''');
    end;
   end;
-----------------------------------------------------------------------------
Randomize  乱数种子.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Randomize;
Example
var

   I: Integer;
 begin
   Randomize;
   for I := 1 to 50 do begin
     { Write to window at random locations }
     Canvas.TextOut(Random(Width), Random(Height), ''''Boo!'''');
   end;
 end;
##Randomize, Random Example
-----------------------------------------------------------------------------
SizeOf    传回X变数的位元数.
-----------------------------------------------------------------------------
Unit  System
函数原型 function SizeOf(X): Integer;
范例  type
     CustRec = record
    Name: string[30];
    Phone: string[14];
     end;
   var
     P: ^CustRec;
   begin
     GetMem(P, SizeOf(CustRec));
     Canvas.TextOut(10, 10, ''''The size of the record is '''' + 
    IntToStr(SizeOf(CustRec)));
     FreeMem (P, SizeOf(CustRec));
     Readln;
   end;
-----------------------------------------------------------------------------
Swap    将一组变数的高低位元交换.
-----------------------------------------------------------------------------
Unit  System
函数原型 function Swap(X);
范例  var
     X: Word;
   begin
     X := Swap($1234);  { $3412 }
   end;
-----------------------------------------------------------------------------
UpCase   将一字元转为大写字母.
-----------------------------------------------------------------------------
Unit  System
函数原型 function UpCase(Ch: Char): Char;
范例  uses Dialogs;
   var
     s : string;
     i : Integer;
   begin
     { Get string from TEdit control }
     s := Edit1.Text;
     for i := 1 to Length(s) do
    s[i] := UpCase(s[i]);
     MessageDlg(''''Here it is in all uppercase: '''' + s, mtInformation,
    [mbOk], 0);
   end;
Example
var

  s : string;
  i : Integer;
begin
  { Get string from TEdit control }
  s := Edit1.Text;
  for i := 1 to Length(s) do
    if i mod 2 = 0 then s[i] := UpCase(s[i]);
  Edit1.Text := s;
end;

===========================================
 Ordinal routines   序列常式
==========================================
Dec    使变数递减.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Dec(var X[ ; N: Longint]);
说明  Dec(X) ==> X:=X-1;
   Dec(X,N) ==> X:=X-N;
范例  var
     IntVar: Integer;
     LongintVar: Longint;
   begin
     Intvar := 10;
     LongintVar := 10;
     Dec(IntVar);  { IntVar := IntVar - 1 }
     Dec(LongintVar, 5); { LongintVar := LongintVar - 5 }
   end;
-----------------------------------------------------------------------------
Inc     使变数递增.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Inc(var X [ ; N: Longint ] );
说明  Inc(X) ==> X:=X-1;
   Inc(X,N) ==> X:=X-N;
范例  var
     IntVar: Integer;
     LongintVar: Longint;
   begin
     Inc(IntVar);  &nb

 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]  ...  下一页 >> 

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