这段是汉字转成区位码,请高手改一下,把区位码转换成汉字,谢谢!!!!
unit qwmu;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, DBTables,printers;type
Tfrmqwm = class(TForm)
edthz: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
memqwm: TMemo;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
frmqwm: Tfrmqwm;
reshz:string;implementation{$R *.dfm}procedure Tfrmqwm.SpeedButton1Click(Sender: TObject);
var
hzlen,i:integer;
phz:pchar;
hzch:char;
curqwm,strhz:string;
begin
strhz:=edthz.Text;
phz:=pchar(edthz.Text);
hzlen:=strlen(phz);
if hzlen=0 then
begin
showmessage('无汉字进行转换');
exit;
end; for i:=0 to hzlen-1 do
begin
hzch:=phz[i];
if ord(hzch)<160 then
begin
showmessage('请删除非汉字字符');
exit;
end;
end; for i:=0 to hzlen-1 do
begin
if i mod 2=0 then
begin
reshz:=reshz+'('+copy(strhz,i+1,2)+')';
// reshz:=reshz+' ';
end; hzch:=phz[i];
curqwm:='00'+inttostr(ord(hzch)-160);
reshz:=reshz+copy(curqwm,strlen(pchar(curqwm))-1,2);
if i mod 2=1 then
begin
// reshz:=reshz+'('+copy(strhz,i,2)+')';
reshz:=reshz+' ';
end;
end;// lblqwm.Caption:=reshz;
memqwm.Text:=reshz;
end;procedure Tfrmqwm.FormCreate(Sender: TObject);
begin
application.Title:='区位码转换';
end;procedure Tfrmqwm.Button2Click(Sender: TObject);
var
inti,intline,intlen:integer;
fprin:textfile;
begin
intlen:=strlen(pchar(reshz));
if intlen=0 then exit;
assignprn(fprin);
rewrite(fprin);
printer.Canvas.Font:=memqwm.Font; intline:=intlen div 90;
// listbox1.Items.Clear;
try for inti:=0 to intline do
begin
// listbox1.Items.Add(copy(reshz,inti*90,90));
writeln(fprin,copy(reshz,inti*90,90));
end; finally
closefile(fprin);
end;
end;end.
unit qwmu;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, DBTables,printers;type
Tfrmqwm = class(TForm)
edthz: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
memqwm: TMemo;
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
frmqwm: Tfrmqwm;
reshz:string;implementation{$R *.dfm}procedure Tfrmqwm.SpeedButton1Click(Sender: TObject);
var
hzlen,i:integer;
phz:pchar;
hzch:char;
curqwm,strhz:string;
begin
strhz:=edthz.Text;
phz:=pchar(edthz.Text);
hzlen:=strlen(phz);
if hzlen=0 then
begin
showmessage('无汉字进行转换');
exit;
end; for i:=0 to hzlen-1 do
begin
hzch:=phz[i];
if ord(hzch)<160 then
begin
showmessage('请删除非汉字字符');
exit;
end;
end; for i:=0 to hzlen-1 do
begin
if i mod 2=0 then
begin
reshz:=reshz+'('+copy(strhz,i+1,2)+')';
// reshz:=reshz+' ';
end; hzch:=phz[i];
curqwm:='00'+inttostr(ord(hzch)-160);
reshz:=reshz+copy(curqwm,strlen(pchar(curqwm))-1,2);
if i mod 2=1 then
begin
// reshz:=reshz+'('+copy(strhz,i,2)+')';
reshz:=reshz+' ';
end;
end;// lblqwm.Caption:=reshz;
memqwm.Text:=reshz;
end;procedure Tfrmqwm.FormCreate(Sender: TObject);
begin
application.Title:='区位码转换';
end;procedure Tfrmqwm.Button2Click(Sender: TObject);
var
inti,intline,intlen:integer;
fprin:textfile;
begin
intlen:=strlen(pchar(reshz));
if intlen=0 then exit;
assignprn(fprin);
rewrite(fprin);
printer.Canvas.Font:=memqwm.Font; intline:=intlen div 90;
// listbox1.Items.Clear;
try for inti:=0 to intline do
begin
// listbox1.Items.Add(copy(reshz,inti*90,90));
writeln(fprin,copy(reshz,inti*90,90));
end; finally
closefile(fprin);
end;
end;end.
function QwToHz(Qw: string): string;
var
v: Integer;
begin
v := StrToInt(Qw);
Result := Chr((v div 100 + 32) or 128) + Chr((v mod 100 + 32) or 128);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(QwToHz(Edit1.Text));
end;