• WinAPI 字符及字符串函数(14): CharToOem、OemToChar


    CharToOemBuff、OemToCharBuff 与 CharToOem、OemToChar 的区别只是前者可以指定要转换的字符数.
    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.
    
  • 相关阅读:
    【芯片】国产MCU替代ST芯片调查
    【生产线】包装如何防止配件漏装
    【标准】运输振动试验
    【bat】批量提取文件夹内文件的名称
    【VBA】从批量excel文件中获取数据
    【滤波器】抗混叠滤波器
    【元器件】晶振TCXO、OCXO
    【C】三点求抛物线顶点
    德卡T10读卡器 读取身份证号码和身份证UID
    C# 执行查询语句,返回DataSet
  • 原文地址:https://www.cnblogs.com/del/p/1328362.html
Copyright © 2020-2023  润新知