unit IntegerInp;

interface

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

type
  TIntInputDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    SEdit: TSpinEdit;
    procedure EditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SEditExit(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
  public
    Result    : integer;
  end;

var
  IntInputDlg: TIntInputDlg;

implementation

{$R *.DFM}

procedure TIntInputDlg.EditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if(Key=VK_RETURN) then
    ModalResult:=mrOk;
end;

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

procedure TIntInputDlg.SEditExit(Sender: TObject);
begin
  if(CheckSpinContens(SEdit,'')) then
    Result:=SEdit.Value
  else
    FocusControl(SEdit);
end;

procedure TIntInputDlg.OKBtnClick(Sender: TObject);
begin
  if(CheckSpinContens(SEdit,'')) then
  begin
    Result:=SEdit.Value;
    ModalResult:=mrOk;
  end
  else
    FocusControl(SEdit);
end;

procedure TIntInputDlg.CancelBtnClick(Sender: TObject);
begin
  if(SEdit.MinValue<>SEdit.MaxValue) then
    SEdit.Value:=SEdit.MinValue
  else
    SEdit.Value:=0;
  Result:=0;
  ModalResult:=mrCancel;
end;

end.
