打印本文 打印本文 关闭窗口 关闭窗口
DELPHI常用函数集及简要范例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数19885  更新时间:2009/4/23 18:30:33  文章录入:mintao  责任编辑:mintao
''The first five characters are '''' +
    Result);
   end;
Examply
uses SysUtils;
const

  S1: PChar = ''''Enterprise''''
  S2: PChar = ''''Enter''''

var
  ComStr: string;
begin
  if StrLIComp(S1, S2, 5) = 0 then
    ComStr := ''''equal''''
  else
    ComStr := ''''different'''';
  Canvas.TextOut(10, 10, ''''The first five characters are '''' + ComStr);
end;


const
   S1: PChar = ''''?????????'''';
   S2: PChar = ''''????????'''';
var
   S: string;
begin
   if StrLIComp( S1, S2, 5) = 0 then S:= ''''?????'''' else S:= ''''????????'''';
   MessageDlg( S1 + #13 + S2 + #13 + ''''?????? '''' + IntToStr( I) + '''' ???????? ????? '''' + S, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
StrLower   将字串全部转为小写字母.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrLower(Str: PChar): PChar;
范例  uses SysUtils;
   const
     S: PChar = ''''A fUnNy StRiNg''''
   begin
     Canvas.TextOut(5, 10, StrPas(StrLower(S)) + '''' '''' +
    StrPas(StrUpper(S)));
   end;
-----------------------------------------------------------------------------
StrMove   从来源字串拷贝n个Bytes到目爬r串.(不含终止位元)
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrMove(Dest, Source: PChar; Count:
    Cardinal): PChar;
范例  uses SysUtils;
   function AHeapaString(S: PChar): PChar;
     { Allocate string on heap }
   var
     L: Cardinal;
     P: PChar;
   begin
     StrNew := nil;
     if (S <> nil) and (S[0] <> #0) then 
    begin
      L := StrLen(S) + 1;
      GetMem(P, L);
      StrNew := StrMove(P, S, L);
    end;
   end;
   procedure DisposeDaString(S: PChar);
     { Dispose string on heap }
   begin
     if S <> nil then FreeMem(S, StrLen(S) + 1);
   end;
   var 
     S: PChar;
   begin
     AHeapaString(S);
     DisposeDaString(S);
   end;
var
   S1, S2: PChar;
begin
   S1:= ''''ABcdEFgh'''';
   StrMove( S2, S1, StrLen( S1) + 1 );
   StrLower( S1);     { S1:= ''''abcdefgh'''' }
   StrUpper( S2);     { S2:= ''''ABCDEFGH'''' }
   MessageDlg( S1 + #13#10 + S2, mtInformation, [mbOk], 0);
end;

-----------------------------------------------------------------------------
StrNew   配置字串空间.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrNew(Str: PChar): PChar;
Example
uses Sysutils;
procedure TForm1.Button1Click(Sender: TObject);

var
  Temp: PChar;
begin
  // Allocate memory.
  Temp := StrNew(PChar(Edit1.Text));
  Application.MessageBox(Temp, ''''StrNew, StrDispose Example'''', MB_OK);
  // Deallocate memory.
  StrDispose(Temp);
end;

const
   S: PChar = ''''??????????? ??????'''';
var
   SNew: PChar;
begin
   SNew:= StrNew( S);
   MessageDlg( ''''S: '''' + S + #13 + ''''SNew: '''' + SNew, mtInformation, [mbOk], 0);
   StrDispose(SNew);
end;

##   StrNew, StrDispose Example
-----------------------------------------------------------------------------
StrPas    将 null-terminated 字串转为Pascal-style 字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrPas(Str: PChar): string;
范例  uses SysUtils;
   const
     A: PChar = ''''I love the smell of Object Pascal in the
     morning.'''';
   var
     S: string[79];
   begin
     S := StrPas(A);
     Canvas.TextOut(10, 10, S);
     { note that the following also works }
     Canvas.TextOut(10, 10, A);
   end;
-----------------------------------------------------------------------------
StrPCopy   拷贝 Pascal-style 字串到null-terminated 字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrPCopy(Dest: PChar; Source: string): PChar;
范例  uses SysUtils;
   var
     A: array[0..79] of Char;
     S: String;
   begin
     S := ''''Honk if you know Blaise.'''';
     StrPCopy(A, S);
     Canvas.TextOut(10, 10, StrPas(A));
   end;

var
   Source: string;
   Dest: array[0..20] of Char;
begin
   Source:= ''''???????? ??????'''';
   StrPCopy( Dest, Source);
   MessageDlg( Dest, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
StrPLCopy  拷贝 Pascal-style 字串到null-terminated 字串.(指定长)
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrPLCopy(Dest: PChar; const Source: string;
    MaxLen: Cardinal): PChar;
-----------------------------------------------------------------------------
StrPos    子字串在母字串中的位置.(第一个位置)
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrPos(Str1, Str2: PChar): PChar;
说明  Str1 母字串
   Str2 子字串
Example
uses SysUtils;

procedure TForm1.Button1Click(Sender TObject);
var
  Location: PChar;
begin
  if StrPos(PChar(Edit1.Text), PChar(Edit2.Text)) <> nil 
then
    ShowMessage(''''Substring found'''')
  else
    ShowMessage(''''Substring not found'''');
end;
------------------
const
   SubStr: PChar = ''''www'''';
var
   S, R: PChar;
begin
   S:= ''''http://www.atrussk.ru/delphi/'''';
   R:= StrPos(S, SubStr);
   if R<>nil then MessageDlg( R, mtInformation, [mbOk], 0) else
       MessageDlg( ''''?? ????????? ?????? URL!'''', mtError, [mbOk], 0);
end;
-----------------------------------------------------------------------------
StrRScan   子字元在母字串中的位置的下一个位址.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrRScan(Str: PChar; Chr: Char): PChar;
范例  { Return pointer to nam

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

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