打印本文 打印本文 关闭窗口 关闭窗口
DELPHI常用函数集及简要范例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数19885  更新时间:2009/4/23 18:30:33  文章录入:mintao  责任编辑:mintao
;{SelLength = 0}
     TmpStr := Copy(Text,1,SelStart-1)+Copy(Text,SelStart+1,255)
    else {Key in [''''A''''..''''Z'''', etc]}
     TmpStr := Copy(Text,1,SelStart)+Key+Copy(Text,SelLength+SelStart+1,255);
    if TmpStr = '''' then Exit;
    { update SelSt to the current insertion point }

    if (Key = Chr(vk_Back)) and (SelSt > 0) then Dec(SelSt)

    else if Key <> Chr(vk_Back) then Inc(SelSt);
    Key := #0; { indicate that key was handled }
    if SelSt = 0 then 
    begin
      Text:= '''';
      Exit;
    end;

   {Now that TmpStr is the currently typed string, see if we can locate a match }

    Found := False;
    for i := 1 to Items.Count do
      if Copy(Items[i-1],1,Length(TmpStr)) = TmpStr then
      begin
        Text := Items[i-1]; { update to the match that was found }
        ItemIndex := i-1;
        Found := True;
        Break;
      end;
    if Found then { select the untyped end of the string }
    begin
      SelStart := SelSt;
      SelLength := Length(Text)-SelSt;

    end
    else Beep;
  end;
end;
##  Copy, Chr, SelStart, SelLength example
-----------------------------------------------------------------------------
High    传回注脚的最大值.
-----------------------------------------------------------------------------
Unit  System
函数原型 function High(X);
范例  [Ordinal type]
   procedure TForm1.Button1Click(Sender: TObject);
   var
     Low_S:String;
     High_S:string;
     S:String;
   begin
     High_S:=''''  High=''''+IntToStr(High(Word));
     Low_S:=''''Low=''''+IntToStr(Low(Word));
     S:=Low_S+High_S;
     Label1.Caption:=S;
   end;

   S:=Low=0  High=65535

   [Array type]
   procedure TForm1.Button1Click(Sender: TObject);
   var
     P : Array[5..21] of Double;
     Low_S:String;
     High_S:string;
     S:String;
   begin
     High_S:=''''  High=''''+IntToStr(High(P));
     Low_S:=''''Low=''''+IntToStr(Low(P));
     S:=Low_S+High_S;
     Label1.Caption:=S;
   end;

   S:=Low=5  High=21

   [String type]
   procedure TForm1.Button1Click(Sender: TObject);
   var
     P : String[23];
     Low_S:String;
     High_S:string;
     S:String;
   begin
     High_S:=''''  High=''''+IntToStr(High(P));
     Low_S:=''''Low=''''+IntToStr(Low(P));
     S:=Low_S+High_S;
     Label1.Caption:=S;
   end;

   S:=Low=0  Hight=23

   P:ShortString;
   S:=Low=0  Hight=255

   P:String;
   长字串不可,会有错误讯号.

   [Open array]
   function Sum( var X: array of Double): Double;
   var
     I: Word;
     S: Double;
   begin
     S := 0;
     { Note that open array index range is always zero-based. }
     for I := 0 to High(X) do S := S + X[I];
    Sum := S;
   end;
Example
function Sum( var X: array of Double): Double;

var
  I: Word;
  S: Real;
begin
  S := 0; { Note that open array index range is always zero-based. }
  for I := 0 to High(X) do S := S + X[I];
  Sum := S;
end;

procedure TForm1.Button1Click(Sender: TObject);

var
  List1: array[0..3] of Double;
  List2: array[5..17] of Double;
  X: Word;
  S, TempStr: string;
begin
  for X := Low(List1) to High(List1) do
      List1[X] := X * 3.4;
  for X := Low(List2) to High(List2) do
      List2[X] := X * 0.0123;
  Str(Sum(List1):4:2, S);
  S := ''''Sum of List1: '''' + S + #13#10;
  S := S + ''''Sum of List2: '''';
  Str(Sum(List2):4:2, TempStr);

  S := S + TempStr;
  MessageDlg(S, mtInformation, [mbOk], 0);
end;
##  Low, High Example
-----------------------------------------------------------------------------
Low    传回注脚的最小值.
-----------------------------------------------------------------------------
Unit  System
函数原型 function Low(X);
说明  Ordinal type  The lowest value in the range of the type
   Array type  The lowest value within the range of the 
       index type of the array
   String type  Returns 0
   Open array  Returns 0
   String parameter Returns 0
-----------------------------------------------------------------------------
Ord    传回列举型态的数值.
-----------------------------------------------------------------------------
Unit  System
函数原型 function Ord(X): Longint;
范例  procedure TForm1.Button1Click(Sender: TObject);
   type
     Colors = (RED,BLUE,GREEN);
   var
     S: string;
   begin
     S := ''''BLUE has an ordinal value of '''' + IntToStr(Ord(RED)) + 
    #13#10;
     S := S+''''The ASCII code for "c" is '''' + IntToStr(Ord(''''c'''')) +  '''' 
    decimal'''';
     MessageDlg(S, mtInformation, [mbOk], 0);
   end;
-----------------------------------------------------------------------------
Round    将实数转为整数.(有四舍五入)
-----------------------------------------------------------------------------
Unit  System
函数原型 function Round(X: Extended): Longint;
范例  var
     S, T: string;
   begin
     Str(1.4:2:1, T);
     S := T + '''' rounds to '''' + IntToStr(Round(1.4)) + #13#10;
     Str(1.5:2:1, T);
     S := S + T + '''' rounds to '''' + IntToStr(Round(1.5)) + #13#10;

 << 上一页  [21] [22] [23] [24] [25] [26] [27] [28] [29] [30]  ...  下一页 >> 

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