以下是我刚写的原代码! unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}type Buffer=array of integer;procedure ConvertHex(const str:string;var Buf:Buffer); var i,C:Integer;function GetSingleHex(const I:Integer):Integer; var T:String; J:Integer; K,H:Byte;begin K:=0; T:=Uppercase(Copy(Str,I,2)); for J:=1 to 2 do begin if J=1 then H:=16 else H:=1; Case T[j] of '0'..'9':K:=K+strtoint(T[j])*H; 'A'..'F':K:=K+(10+(ord(T[j])-$41))*H; end; end; result:=K; end;begin SetLength(Buf,trunc((Length(Str)+1)/3)); C:=0; I:=1; while I<Length(Str) do begin Buf[C]:=GetSingleHex(I); Inc(C); I:=I+3; end; end;procedure TForm1.Button1Click(Sender: TObject); var P:Buffer; j:integer; begin ConvertHex(Edit1.Text,P); Edit2.Text:=''; For J:=0 to Length(P)-1 do Edit2.Text:=Edit2.Text+IntTostr(P[j])+','; end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}type
Buffer=array of integer;procedure ConvertHex(const str:string;var Buf:Buffer);
var
i,C:Integer;function GetSingleHex(const I:Integer):Integer;
var
T:String;
J:Integer;
K,H:Byte;begin
K:=0;
T:=Uppercase(Copy(Str,I,2));
for J:=1 to 2 do
begin
if J=1 then
H:=16
else
H:=1;
Case T[j] of
'0'..'9':K:=K+strtoint(T[j])*H;
'A'..'F':K:=K+(10+(ord(T[j])-$41))*H;
end;
end;
result:=K;
end;begin
SetLength(Buf,trunc((Length(Str)+1)/3));
C:=0;
I:=1;
while I<Length(Str) do
begin
Buf[C]:=GetSingleHex(I);
Inc(C);
I:=I+3;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
P:Buffer;
j:integer;
begin
ConvertHex(Edit1.Text,P);
Edit2.Text:='';
For J:=0 to Length(P)-1 do
Edit2.Text:=Edit2.Text+IntTostr(P[j])+',';
end;end.