unit Unit2; // Enter Address

interface

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

type
  TForm2 = class(TForm)
    LabeledEdit1: TLabeledEdit;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure LabeledEdit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Function HexToInt(Hex:String):Integer;

var
  Form2: TForm2;
  StartAddress:Integer;

implementation

{$R *.dfm}

// Преобразование Hex в Int
Function HexToInt(Hex:String):Integer;
Const
ExtF:Set of char=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'];
Values:Array [0..15] of Char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
Var
i,j:Integer;
DD:Array [0..3] of Byte;
Begin
if(Hex='')or(Length(Hex)>4)then Begin HexToInt:=-1;Exit end;
for i:=1 to Length(Hex)do
    if not(Hex[i] in ExtF)then
       Begin
       HexToInt:=-1;
       Exit;
       end;
for i:=0 to 3 do DD[i]:=0;
for i:=Length(Hex) downto 1 do
    for j:=0 to 15 do if UpperCase(Hex[i])=Values[j] then DD[Length(Hex)-i]:=j;
HexToInt:=4096*DD[3]+256*DD[2]+16*DD[1]+DD[0];
end;

// Инициализация формы
procedure TForm2.FormShow(Sender: TObject);
begin
LabeledEdit1.Text:='100';
StartAddress:=-1;
end;

// Ввод значения
procedure TForm2.Button1Click(Sender: TObject);
begin
StartAddress:=HextoInt(LabeledEdit1.Text);
if StartAddress=-1 then ShowMessage('Error: Incorrect Values are Entered!')
                   else Form2.Close;
end;

// Проверка на Enter
procedure TForm2.LabeledEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#$0D then Begin
                  Key:=#$00;
                  Button1.Click;
                  end;
end;

end.
