Caption := IntToStr(Ord(‘A‘));
Caption := IntToStr(Ord(WideString(‘的‘)[1]));
//====================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
cMinGBCByte = 161; //最小国标字节
cMaxGBCByte = 254; //最大国标字节
function StrToGBC(mStr: string): string; { 返回汉字所对应的区位码 }
begin
if Length(mStr) = 2 then
Result := FormatFloat(‘00‘, Ord(mStr[1]) - cMinGBCByte + 1)
+ FormatFloat(‘00‘, Ord(mStr[2]) - cMinGBCByte + 1)
else Result := ‘‘;
end; { StrToGBC }
function GBCToStr(mStr: string): string; { 返回区位码所对应的汉字 }
var
I, J: Integer;
begin
I := StrToIntDef(mStr, 0);
J := I mod 100;
I := I div 100;
I := I + cMinGBCByte - 1;
J := J + cMinGBCByte - 1;
Result := Chr(I) + Chr(J)
end; { GBCToStr }
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := GBCToStr(Edit1.Text)
end;
end.