最近在下班业余时间学习下delphi和C++,用delphi写界面,C++写核心代码,希望以后可以用delphi和c++写一些自己的程序出来,也是最近才学到运算符于是写了2个小程序以巩固学的东西,此文章就暂时贴出来十进制和十六进制之间的转化的程序,具体代码如下:
 
unit Unit1;
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.
 
 
delphi实现十进制与十六进制之间的转化 _职场