转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
DELPHI常用函数集及简要范例         ★★★★

DELPHI常用函数集及简要范例

作者:闵涛 文章来源:闵涛的学习笔记 点击数:19872 更新时间:2009/4/23 18:30:33
nbsp; else begin
   ix := ColumnToSort - 1;
   Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
  end;
end;
##  OnColumnClick, AlphaSort, OnCompare, CompareText example
-----------------------------------------------------------------------------
Concat    将字串相加.
-----------------------------------------------------------------------------
Unit  System
函数原型 function Concat(s1 [, s2,..., sn]: string): string;
说明  与 S := S1 + S2 + S3 ...; 相同.
范例  var
     S: string;
   begin
     S := Concat(''''ABC'''', ''''DEF''''); { ''''ABCDE'''' }
   end;

var
   S: string;
begin
   S:= ''''? ''''+ ''''???? ''''+ ''''???????? ??????'''';
   S:= Concat(''''? '''', ''''???? '''', ''''???????? ??????'''');
      // ? ????? ??????? S := ''''? ???? ???????? ??????''''
end;
-----------------------------------------------------------------------------
Copy    从母字串拷贝至另一个字串.
-----------------------------------------------------------------------------
Unit  System
函数原型 function Copy(S: string; Index, Count: Integer): string;
说明  S  : 字串.
   Indexd : 从第几位开始拷贝.
   Count : 总共要拷贝几位.
范例  var S: string;
   begin
     S := ''''ABCDEF'''';
     S := Copy(S, 2, 3); { ''''BCD'''' }
   end;
----------------
var
   S: string;
begin
   S:= ''''??????'''';
   S:= Copy( S, 3, 4);     // S := ''''????''''
end;
---------------
Example
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
  Found: boolean;
  i,SelSt: Integer;
  TmpStr: string;
begin
  { first, process the keystroke to obtain the current string }
  { This code requires all items in list to be uppercase}
  if Key in [''''a''''..''''z''''] then Dec(Key,32); {Force Uppercase only!}
  with (Sender as TComboBox) do
  begin
    SelSt := SelStart;
    if (Key = Chr(vk_Back)) and (SelLength <> 0) then
     TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelLength+SelStart+1,255)

    else if Key = Chr(vk_Back) then {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;
-----------------------
procedure TComponentEditor.Copy;
var
  AFormat : Word;
  AData,APalette : THandle;
begin
  with Component as TImage do
  begin
    Picture.SaveToClipBoardFormat(AFormat,AData,APalette);
    ClipBoard.SetAsHandle(AFormat,AData);
  end;
end;


## Copy, Chr, SelStart, SelLength example

-----------------------------------------------------------------------------
Delete    删除字串中的数个字元.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Delete(var S: string; Index, Count:Integer);
说明  S  : 字串.
   Indexd : 从第几位开始删.
   Count : 总共要删几位.
范例  var
     s: string;
   begin
     s := ''''Honest Abe Lincoln'''';
     Delete(s,8,4);
     Canvas.TextOut(10, 10, s); { ''''Honest Lincoln'''' }
   end;
var
   S: string;
begin
   S:= ''''???????, ??????, ??????????!'''';
   Delete(S, 8, 1);     // S := ''''??????? ??????, ??????????!''''
   MessageDlg(S, mtWarning, [mbOK],0); 
end;
-----------------------------------------------------------------------------
NewStr   在 heap 中配置一个新的字串空间给PString 指标.
-----------------------------------------------------------------------------
DisposeStr  在 heap 中释放一个字串空间 PString指标.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function NewStr(const S: string): PString;
函数原型 procedure DisposeStr(P: PString);
说明  S  : 字串.
   Pstring : 新的字串指标.
范例  var
     P: PString;
     S: string;
   begin
     S := ''''Ask me about Blaise'''';
     P := NewStr(S);
     DisposeStr(P):
   end;
-----------------------------------------------------------------------------
Insert    将一个子字串插入另一个字串中.
-----------------------------------------------------------------------------
Unit  System
函数原型 procedure Insert(Source: string; var S: string; Index: Integer);
说明  Source : 子字串.
   S  : 被插入的母字串.
   Indexd  : 从第几位开始插入.
范例  var
     S: string;
   begin
     S := ''''Honest Lincoln'''';
     Insert(''''Abe '''', S, 8); { ''''Honest Abe Lincoln'''' }
   end;
var
   S: string;
begin
   S:= ''''??????? ?????? ??????????.'''';
   Insert( ''''!'''', S, 8);       { S := ''''???????! ?????? ??????????.''''}
   MessageDlg( S, mtWarning, [mbOK],0); 
end;
-----------------------------------------------------------------------------
IntToHex   将 Int 转为&n

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


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台