Delphi Call WINAPI Character and string function (in): Lstrlen

Source: Internet
Author: User
Tags integer

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.