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}
procedure TForm1.Button1Click(Sender: TObject);
var
p: PChar;
buf: array[0..255] of Char;
n1,n2: Integer;
begin
p := 'Delphi';
buf := 'Delphi';
n1 := lstrlen(p);
n2 := lstrlen(buf);
ShowMessageFmt('%d,%d', [n1,n2]); {6,6}
end;
procedure TForm1.Button2Click(Sender: TObject);
var
n1,n2: Integer;
begin
n1 := lstrlenA('萬一的 Delphi 博客');
n2 := lstrlenW('萬一的 Delphi 博客');
ShowMessageFmt('%d,%d', [n1,n2]); {18,13}
end;
end.