问题来源: http://www.cnblogs.com/del/archive/2008/07/10/1239621.html#1250359

代码文件:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{初始化测试数据}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Text := '004500FF';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  a,b: Integer;
begin
  {把 Edit1 中的十六进制字符串转换成整数}
  b := StrToIntDef('$' + Edit1.Text, 0);
  {通过汇编的方式把 b 赋给 a; 这相当于 a := b;}
  asm
    mov eax, b
    mov a, eax
  end;
  {看看 a 的值}
  ShowMessage(IntToHex(a, 8)); {004500FF}
end;

end.


窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 206
  ClientWidth = 339
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 104
    Top = 56
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
  end
  object Button1: TButton
    Left = 128
    Top = 112
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end

posted on 2008-07-10 10:51  万一  阅读(1483)  评论(3编辑  收藏  举报