南
南宫吹云
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做的是在一个EDIT中输入十六进制数,在另一个EDIT中显示此数值的字符,显示ASCII码时
正常,当显示汉字时不能正常显示,源码如下,请高手帮我看一下:
窗体上共有三个EDIT:
EDIT1:显示输入的字符或由十六进制转换而成的字符;
EDIT2:显示输入字符的十进制值;
EDIT3:显示输入字符的十六进制数或输入十六进制数。
function turnnum(c:char):integer;
begin
result:=0;
case c of
'0'..'9':result:=strtoint(c);
'a','A':result:=10;
'b','B':result:=11;
'c','C':result:=12;
'd','D':result:=13;
'e','E':result:=14;
'f','F':result:=15;
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
i:integer;
begin
if activecontrol=edit1 then
begin
edit2.text:='';
edit3.text:='';
for i:=1 to length(edit1.text) do
begin
edit2.text:=edit2.text+inttostr(ord(edit1.text))+' ';
edit3.text:=edit3.text+inttohex(ord(edit1.text),2)+' ';
end;
end;
end;
procedure TForm1.Edit3Change(Sender: TObject);
var
i,j:integer;
begin
if activecontrol=edit3 then
begin
if edit3.text='' then exit;
edit1.text:='';
edit2.Text:='';
i:=1;
if length(edit3.text) mod 2=0 then
begin
repeat
j:=turnnum(edit3.Text)*16+turnnum(edit3.Text[i+1]);
edit1.Text:=edit1.Text+chr(j);
edit2.Text:=edit2.Text+inttostr(j)+' ';
inc(i,2);
until i>=length(edit3.text);
end;
end;
end;
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','a'..'f','A'..'F',#8,#13]) then
key:=chr(0);
end;
正常,当显示汉字时不能正常显示,源码如下,请高手帮我看一下:
窗体上共有三个EDIT:
EDIT1:显示输入的字符或由十六进制转换而成的字符;
EDIT2:显示输入字符的十进制值;
EDIT3:显示输入字符的十六进制数或输入十六进制数。
function turnnum(c:char):integer;
begin
result:=0;
case c of
'0'..'9':result:=strtoint(c);
'a','A':result:=10;
'b','B':result:=11;
'c','C':result:=12;
'd','D':result:=13;
'e','E':result:=14;
'f','F':result:=15;
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
i:integer;
begin
if activecontrol=edit1 then
begin
edit2.text:='';
edit3.text:='';
for i:=1 to length(edit1.text) do
begin
edit2.text:=edit2.text+inttostr(ord(edit1.text))+' ';
edit3.text:=edit3.text+inttohex(ord(edit1.text),2)+' ';
end;
end;
end;
procedure TForm1.Edit3Change(Sender: TObject);
var
i,j:integer;
begin
if activecontrol=edit3 then
begin
if edit3.text='' then exit;
edit1.text:='';
edit2.Text:='';
i:=1;
if length(edit3.text) mod 2=0 then
begin
repeat
j:=turnnum(edit3.Text)*16+turnnum(edit3.Text[i+1]);
edit1.Text:=edit1.Text+chr(j);
edit2.Text:=edit2.Text+inttostr(j)+' ';
inc(i,2);
until i>=length(edit3.text);
end;
end;
end;
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','a'..'f','A'..'F',#8,#13]) then
key:=chr(0);
end;