unit Step2a;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Spin, MathDef, Step1, MiscRoutines;

type
  TStepTwoForm_A = class(TForm)
    BackwardButton: TButton;
    ForwardButton: TButton;
    CancelButton: TButton;
    Panel: TPanel;
    ImgPanel: TPanel;
    Image: TImage;
    TextPanel: TPanel;
    InfoLabel: TLabel;
    GroupBox1: TGroupBox;
    KEdit: TSpinEdit;
    NEdit: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure FormShow(Sender: TObject);
    procedure BackwardButtonClick(Sender: TObject);
    procedure ForwardButtonClick(Sender: TObject);
    procedure CancelButtonClick(Sender: TObject);
    procedure KEditExit(Sender: TObject);
    procedure NEditExit(Sender: TObject);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  public
    Result : TDirResult;
  private
    CheckRes : Boolean;
  end;

var
  StepTwoForm_A: TStepTwoForm_A;

implementation

{$R *.DFM}

procedure TStepTwoForm_A.FormShow(Sender: TObject);
begin
  Result:=wCancel;
end;

procedure TStepTwoForm_A.BackwardButtonClick(Sender: TObject);
begin
  KEdit.Value:=ValidInteger(KEdit);
  NEdit.Value:=ValidInteger(NEdit);
  Result:=wBack;
  Close;
end;

procedure TStepTwoForm_A.ForwardButtonClick(Sender: TObject);
begin
  KEditExit(Self);
  if(not CheckRes) then exit;
  NEditExit(Self);
  if(not CheckRes) then exit;
  Result:=wForward;
  Close;
end;

procedure TStepTwoForm_A.CancelButtonClick(Sender: TObject);
begin
  Result:=wCancel;
  Close;
end;

procedure TStepTwoForm_A.KEditExit(Sender: TObject);
begin
  CheckRes:=CheckSpinContens(KEdit,'Количество факторов');
  if(not CheckRes) then
    FocusControl(KEdit);
end;

procedure TStepTwoForm_A.NEditExit(Sender: TObject);
begin
  CheckRes:=CheckSpinContens(NEdit,'Количество опытов');
  if(not CheckRes) then
    FocusControl(NEdit);
end;

procedure TStepTwoForm_A.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
  188: // '<'
    if(ssCtrl in Shift) then
      BackwardButtonClick(Self);
  190: // '>'
    if(ssCtrl in Shift) then
      ForwardButtonClick(Self);
  VK_ESCAPE:
    begin
      BackwardButtonClick(Self);
      Result:=wCancel;
      Close;
    end;
  end;
end;

end.
