现在需要把字符类型转换成16进制发送出去,不会啦,我用的是mscomm控件,谁能帮帮我啊,谢谢啦
以下是字符/16进制和16进制/字符的源程序.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPMan;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
XPManifest1: TXPManifest;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); //字符转换/16进制(汉字和其他任何字符均可)
var
i,o:integer;
begin
edit2.text:= '';
for i := 1 to Edit1.GetTextLen() do
begin
o := Ord(Edit1.Text[i]);
edit2.text:= edit2.text + IntToHex(o, 2);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);//16进制/字符
var
i,n:integer;
c,c1:string;
begin
try
edit1.text:='';
n:=1;
for i := 1 to Edit2.GetTextLen()div 2 do
begin
c:=copy(edit2.Text,n,2);
n:=n+2;
c1:=c1+CHR(StrToInt('$'+C));
end;
edit1.Text:=c1;
except
on EConvertError do showmessage('内码数据输入有误!');
end;
end;
procedure TForm1.Button3Click(Sender: TObject);//清空数据
begin
edit1.text:='';
edit2.text:='';
end;
end.
[此贴子已经被作者于2006-9-26 23:40:19编辑过]