interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Change = object
public
function DexToHex(Num1:String):string;
function HexToDex(Num2:String):string;
end;
var
Form1: TForm1;
implementation
function Change.DexToHex(Num1:string):string;
var
local1:integer;
begin
local1:= StrToInt(Num1);
result:= IntToHex(local1,2) ;
end;
function Change.HexToDex(Num2:string):string;
begin
result:= IntToStr( StrToInt('$'+Num2));
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Info1:Change;
Dexnum:string;
begin
if(Edit1.Text = '')
then
ShowMessage('请输入一个十进制的数!')
else
Dexnum:= Edit1.text;
Edit2.Text:= Info1.DexToHex(Dexnum) ;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Info2:Change;
Hexnum:string;
begin
if (Edit2.Text = '')
then
ShowMessage('请输出一个十六进制的数!')
else
Hexnum:= Edit2.text;
Edit1.Text:= Info2.HexToDex(Hexnum);
end;
end.