10进制与16进制间的数值互转

其实,以上程序还有一个问题没有解决,就是当你输入大于32位的数值时程序将会出错,这个问题留待以后基础打牢点再解决了,呵呵。。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    StaticText1: TStaticText; //这组件跟标签label效果差不多
    StaticText2: TStaticText;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private

    { Private declarations }
  public

    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject); //都是delphi自带函数,没什么好说的
var
  a:Integer;
begin
  a:=StrToInt(Edit1.Text);
  Edit2.Text:=IntToHex(a,1);
end;
procedure TForm1.Button2Click(Sender: TObject); //都是delphi自带函数,没什么好说的
var
  i:Integer;
begin
  i:=strtoint('$'+(Edit2.Text));  //加'$'后,原本的字符串就成了16进制数
  Edit1.Text:=IntToStr(i);
end;
end.

相关文章:

  • 2021-08-28
  • 2021-12-10
  • 2022-02-11
  • 2022-12-23
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案