StrComp 和 StrIComp 都是对比 PChar 字串的大小的函数, 只是后者不区分大小写.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//测试 1:
procedure TForm1.Button1Click(Sender: TObject);
var
  n1,n2,n3,n4: Integer;
begin
  n1 := StrComp('A', 'C');
  n2 := StrComp('C', 'A');
  n3 := StrComp('A', 'A');
  n4 := StrComp('a', 'A');
  ShowMessageFmt('%d, %d, %d, %d', [n1, n2, n3, n4]); {-2, 2, 0, 32}
end;

//测试 2:
procedure TForm1.Button2Click(Sender: TObject);
var
  p1,p2: PChar;
  n1,n2,n3: Integer;
begin
  p1 := 'abc';
  p2 := 'bcd';
  n1 := StrComp(p1, p2);

  p1 := 'Abc';
  p2 := 'bcd';
  n2 := StrComp(p1, p2);

  p1 := '万一';
  p2 := 'WanYi';
  n3 := StrComp(p1, p2);

  ShowMessageFmt('%d, %d, %d', [n1, n2, n3]); {-1, -33, 0, 118}
end;

end.

SysUtils 单元下的公用函数目录

posted on 2008-05-12 14:31  万一  阅读(3046)  评论(0编辑  收藏  举报