unit FloatInp;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, ExtCtrls, MiscRoutines;

type
  TFloatInputDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    Edit: TEdit;
    procedure FormShow(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditExit(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
  public
    Result : double;
  end;

var
  FloatInputDlg: TFloatInputDlg;

implementation

{$R *.DFM}

procedure TFloatInputDlg.FormShow(Sender: TObject);
begin
  FocusControl(Edit);
end;

procedure TFloatInputDlg.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    VK_RETURN: OkBtnClick(nil);
    VK_ESCAPE: CancelBtnClick(nil);
  end;
end;

procedure TFloatInputDlg.EditExit(Sender: TObject);
begin
  if(not ContainDouble(Edit.Text,Result,'')) then
    FocusControl(Edit);
end;

procedure TFloatInputDlg.OKBtnClick(Sender: TObject);
begin
  if(ContainDouble(Edit.Text,Result,'')) then
    ModalResult:=mrOk
  else
    FocusControl(Edit);
end;

procedure TFloatInputDlg.CancelBtnClick(Sender: TObject);
begin
  Edit.Text:='';
  Result:=0;
  ModalResult:=mrCancel;
end;

end.
