Delphi calls WINAPI characters and String functions: Chartooem, Oemtochar

Source: Internet
Author: User

The difference between Chartooembuff, Oemtocharbuff and Chartooem and Oemtochar is that the former can specify the number of characters to convert. unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
type
 TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  Button3: TButton;
  Button4: TButton;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure Button4Click(Sender: TObject);
  procedure Button3Click(Sender: TObject);
 end;
Var

 Form1: TForm1;
implementation
{$R *.dfm}
Procedure Tform1.button1click (Sender:tobject);var
 Buf: PWideChar;
 AnsiBuf: array[0..255] of AnsiChar;
begin
 Buf := '万一的 Delphi 博客';
 CharToOem(Buf, AnsiBuf);
 ShowMessage(string(AnsiBuf)); {万一的 Delphi 博客}
 FillChar(AnsiBuf, Length(AnsiBuf), #0);
 CharToOemBuff(Buf, AnsiBuf, 6);
 ShowMessage(string(AnsiBuf)); {万一的 De}
end;
Procedure Tform1.button2click (Sender:tobject);var
 str: string;
 p: PAnsiChar;
begin
 str := '万一的 Delphi 博客';
 p := GetMemory(256);
 CharToOem(PChar(str), p);
 ShowMessage(string(p)); {万一的 Delphi 博客}
 FreeMemory(p);
 p := GetMemory(256);
 CharToOemBuff(PChar(str), p, 6);
 ShowMessage(string(p)); {万一的 De}
 FreeMemory(p);
end;
Procedure Tform1.button3click (Sender:tobject);var
 AnsiBuf: PAnsiChar;
 Buf: array[0..255] of Char;
begin
 AnsiBuf := '万一的 Delphi 博客';
 OemToChar(AnsiBuf, buf);
 ShowMessage(string(Buf)); {万一的 Delphi 博客}
 FillChar(Buf, Length(Buf), #0);
 OemToCharBuff(AnsiBuf, buf, 6);
 ShowMessage(string(Buf)); {万一的}
end;
Procedure Tform1.button4click (Sender:tobject);var
 AnsiStr: AnsiString;
 p: PChar;
begin
 AnsiStr := '万一的 Delphi 博客';
 p := StrAlloc(256);
 OemToChar(PAnsiChar(AnsiStr), p);
 ShowMessage(string(p)); {万一的 Delphi 博客}
 StrDispose(p);
 p := StrAlloc(256);
 OemToCharBuff(PAnsiChar(AnsiStr), p, 6);
 ShowMessage(string(p)); {万一的}
 StrDispose(p);
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.