打印本文 打印本文 关闭窗口 关闭窗口
DELPHI常用函数集及简要范例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数19885  更新时间:2009/4/23 18:30:33  文章录入:mintao  责任编辑:mintao
p;StrCat(S1, P1);     { S1 := ''''??????-??????????'''' }
   StrCat(S2, P2);     { S2 := ''''??????-????????'''' }
   MessageDlg( S1+ #13+ S2, mtInformation, [mbOk], 0);
end;

##StrCopy, StrCat Example
-----------------------------------------------------------------------------
StrComp   比较两字串大小.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrComp(Str1, Str2 : PChar): Integer;
范例  uses SysUtils;
   const
     S1: PChar = ''''Wacky'''';
     S2: PChar = ''''Code'''';
   var
     C: Integer;
     Result: string;
   begin
     C := StrComp(S1, S2);
     if C < 0 then Result := '''' is less than '''' else
    if C > 0 then Result := '''' is greater than '''' else
     Result := '''' is equal to '''';
     Canvas.TextOut(10, 10, StrPas(S1) + Result +
    StrPas(S2));
   end;
Example
uses SysUtils;
procedure TForm1.Button1Click(Sender: TObject);

var
  Msg: string;
  CompResult: Integer;
begin
  Msg := Edit1.Text;
  CompResult := StrComp(PChar(Edit1.Text), PChar(Edit2.Text));
  if CompResult < 0 then
    Msg := Msg + '''' is less than ''''
  else if CompResult > 0 then
    Msg := Msg + '''' is greater than ''''
  else
    Msg := Msg + '''' is equal to ''''
  Msg := Msg + Edit2.Text;
  ShowMessage(Msg);
end;

var
   S1,S2: PChar;
   I: Integer;
   Res: string;
begin
   S1:= ''''Company'''';
   S2:= ''''COMPANY'''';
   I:= StrComp(S1, S2);
   if I>0 then Res:= ''''>'''' else
      if I<0 then Res:= ''''<'''' else Res:= ''''='''';
   MessageDlg(S1+ Res+ S2, mtInformation, [mbOk], 0);
end;
-----------------------------------------------------------------------------
StrCopy   拷贝字串.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrCopy(Dest, Source: PChar): PChar;
范例  uses SysUtils;
   var
     S: array[0..12] of Char;
   begin
     StrCopy(S, ''''ObjectPascal'''');
     Canvas.TextOut(10, 10, StrPas(S));
   end;
Example
procedure TForm1.Button1Click(Sender: TObject);
var
  Buffer: PChar;
begin
  GetMem(Buffer,Length(Label1.Caption) + Length(Edit1.Text) + 1);
  StrCopy(Buffer, PChar(Label1.Caption));
  StrCat(Buffer, PChar(Edit1.Text));
  Label1.Caption := Buffer;
  Edit1.Clear;
  FreeMem(Buffer);
end;
##  StrCopy, StrCat Example
-----------------------------------------------------------------------------
StrDispose  释放StrAlloc or StrNew所配置的空间.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 procedure StrDispose(Str: PChar);
范例  uses SysUtils;
   const
     S: PChar = ''''Nevermore'''';
   var
     P: PChar;
   begin
     P := StrNew(S);
     Canvas.TextOut(10, 10, StrPas(P));
     StrDispose(P);
   end;
-----------------------------------------------------------------------------
StrECopy   拷贝字串并传回字串结束位址.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrECopy(Dest, Source: PChar): PChar;
范例  uses SysUtils;
   const
     Turbo: PChar = ''''Object'''';
     Pascal: PChar = ''''Pascal'''';
   var
     S: array[0..15] of Char;
   begin
     StrECopy(StrECopy(StrECopy(S, Turbo), '''' ''''), Pascal);
     Canvas.TextOut(10, 10, StrPas(S));
   end;
Example
uses SysUtils;
const

  Turbo: PChar = ''''Object'''';
  Pascal: PChar = ''''Pascal'''';
 var
  S: array[0..15] of Char;
begin
  StrECopy(StrECopy(StrECopy(S, Turbo), '''' ''''), Pascal);
  Canvas.TextOut(10, 10, string(S));
end;
-----------------------------------------------------------------------------
StrEnd    传回字串结束位址.
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrEnd(Str: PChar): PChar;
范例  uses SysUtils;
   const
     S: PChar = ''''Yankee Doodle'''';
   begin
     Canvas.TextOut(5, 10, ''''The string length of "'''' + StrPas(S)
    + ''''" is '''' +IntToStr(StrEnd(S) - S));
   end;
Example
procedure TForm1.Button1Click(Sender: TObject);

var
  TextBuffer: PChar;
  Ptr: PChar;
begin
  GetMem(TextBuffer, Length(Edit1.Text)+1);
  StrCopy(TextBuffer, PChar(Edit1.Text));
  Ptr := StrEnd(TextBuffer);
  Label1.Caption := '''';
  while Ptr >= TextBuffer do
  begin
    Ptr := Ptr ? 1;
    Label1.Caption := Label1.Caption + Ptr^;
  end;
  FreeMem(TextBuffer);
end;

var
   Str: PChar;
   L: Word;
begin
   ...
   L:= StrEnd(Str) - Str;
   ...
end;
-----------------------------------------------------------------------------
StrIComp   比较两字串大小.(不分大小写)
-----------------------------------------------------------------------------
Unit  SysUtils
函数原型 function StrIComp(Str1, Str2:PChar): Integer;
范例  uses SysUtils;
   const
     S1: PChar = ''''Wacky'''';
     S2: PChar = ''''Code'''';
   var
     C: Integer;
     Result: string;
   begin
     C := StrIComp(S1, S2);
     if C < 0 then Result := '''' is less than '''' else
    if C > 0 then Result := '''' is greater than '''' else
     Result := '''' is equal to '''';
     Canvas.TextOut(10, 10, StrPas(S1) + Result +
    StrPas(S2));
   end;
xample
uses SysUtils;
procedure TForm1.Button1Click(Sender: TObject);

var
  Msg: string;
  CompResult: Integer;
begin
  Msg := Edit1.Text;
  CompResult := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
  if CompResult < 0 then
    Msg := Msg + '''' is less than ''''
  else if CompResult > 0 then
    Msg := Msg + '''' is greater than ''''
&n

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

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