来自 新葡8455编程 2020-02-26 21:34 的文章
当前位置: 新葡棋牌京官网app > 新葡8455编程 > 正文

delphi字符串转换到指定格式的宽字符

本例效果图:

图片 1


代码文件:


unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Memo1: TMemo;    Button1: TButton;    Edit1: TEdit;    procedure FormCreate(Sender: TObject);    procedure Button1Click(Sender: TObject);    procedure Memo1Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var  str: string;  pcw: PWideChar;  cw: WideChar;  i: Integer;begin  Memo1.Clear;  str := Edit1.Text;  pcw := PWideChar(str);  for i := 0 to StrLen(pcw) - 1 do  begin    cw := (pcw+i)^;    Memo1.Lines.Add(Format('$%.4x', [Ord(cw)]));    //Memo1.Lines.Add(Format('$%.4x', [Ord(str[i+1])])); {也可以用这句替换上面两行}  end;end;procedure TForm1.FormCreate(Sender: TObject);begin  Memo1.Clear;  Memo1.Align := alLeft;  Memo1.ScrollBars := ssVertical;end;procedure TForm1.Memo1Click(Sender: TObject);var  str: string;begin  str := Memo1.Lines[Memo1.CaretPos.Y];  Text := WideChar(StrToIntDef(str, 0));end;end.

本文由新葡棋牌京官网app发布于新葡8455编程,转载请注明出处:delphi字符串转换到指定格式的宽字符

关键词: