unit SurfStep2;

interface

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

type
  TSurfaceStep2 = class(TWizardTemplateForm)
    Label1: TLabel;
    GBFirst: TGroupBox;
    LFL: TLabel;
    LFR: TLabel;
    EFirstLeft: TEdit;
    EFirstRight: TEdit;
    SEFirstPoints: TSpinEdit;
    LFP: TLabel;
    GBSecond: TGroupBox;
    ESecondLeft: TEdit;
    ESecondRight: TEdit;
    SESecondPoints: TSpinEdit;
    LSL: TLabel;
    LSR: TLabel;
    LSP: TLabel;
    procedure EFirstLeftExit(Sender: TObject);
    procedure EFirstRightExit(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure SEFirstPointsExit(Sender: TObject);
    procedure ESecondLeftExit(Sender: TObject);
    procedure ESecondRightExit(Sender: TObject);
    procedure SESecondPointsExit(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    function  Validate:Boolean;
    procedure Clean;
  public
    FirstLeft,
    FirstRight,
    SecondLeft,
    SecondRight : double;
    function GoForward:Boolean;override;
    function GoBackward:Boolean;override;
  end;

var
  SurfaceStep2: TSurfaceStep2;

implementation

{$R *.DFM}

function TSurfaceStep2.Validate;
begin
  Result:=
    ContainDouble(EFirstLeft.Text,FirstLeft,LFL.Caption) and
    ContainDouble(EFirstRight.Text,FirstRight,LFR.Caption) and
    CheckSpinContens(SEFirstPoints,LFP.Caption) and
    ContainDouble(ESecondLeft.Text,SecondLeft,LSL.Caption) and
    ContainDouble(ESecondRight.Text,SecondRight,LSR.Caption) and
    CheckSpinContens(SESecondPoints,LSP.Caption);
  if(Result) then
  begin
    if(FirstLeft>=FirstRight) then
    begin
      Warning('Первая правая граница должна быть больше левой.');
      Result:=False;
      exit;
    end;
    if(SecondLeft>=SecondRight) then
    begin
      Warning('Вторая правая граница должна быть больше левой.');
      Result:=False;
      exit;
    end;
  end;
end;

procedure TSurfaceStep2.Clean;
begin
  EFirstLeft.Text:=ValidDouble(EFirstLeft.Text);
  EFirstRight.Text:=ValidDouble(EFirstRight.Text);
  ESecondLeft.Text:=ValidDouble(ESecondLeft.Text);
  ESecondRight.Text:=ValidDouble(ESecondRight.Text);
  SEFirstPoints.Value:=ValidInteger(SEFirstPoints);
  SESecondPoints.Value:=ValidInteger(SESecondPoints);
end;

function TSurfaceStep2.GoForward;
begin
  Result:=True;
end;

function TSurfaceStep2.GoBackward;
begin
  Result:=True;
end;

procedure TSurfaceStep2.FormShow(Sender: TObject);
begin
  inherited;
  FirstLeft:=StrToFloat(EFirstLeft.Text);
  FirstRight:=StrToFloat(EFirstRight.Text);
  SecondLeft:=StrToFloat(ESecondLeft.Text);
  SecondRight:=StrToFloat(ESecondRight.Text);
end;

procedure TSurfaceStep2.EFirstLeftExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(EFirstLeft.Text,FirstLeft,LFL.Caption)) then
    FocusControl(EFirstLeft);
end;

procedure TSurfaceStep2.EFirstRightExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(EFirstRight.Text,FirstRight,LFR.Caption)) then
    FocusControl(EFirstRight);
end;

procedure TSurfaceStep2.SEFirstPointsExit(Sender: TObject);
begin
  inherited;
  if(not CheckSpinContens(SEFirstPoints,LFP.Caption)) then
    FocusControl(SEFirstPoints);
end;

procedure TSurfaceStep2.ESecondLeftExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(ESecondLeft.Text,SecondLeft,LSL.Caption)) then
    FocusControl(ESecondLeft);
end;

procedure TSurfaceStep2.ESecondRightExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(ESecondRight.Text,SecondRight,LSR.Caption)) then
    FocusControl(ESecondRight);
end;

procedure TSurfaceStep2.SESecondPointsExit(Sender: TObject);
begin
  inherited;
  if(not CheckSpinContens(SESecondPoints,LSP.Caption)) then
    FocusControl(SESecondPoints);
end;

procedure TSurfaceStep2.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if(ChooseResult(Key,ModalResult)<>mrNone) then
    ModalResult:=ChooseResult(Key,ModalResult);
end;

procedure TSurfaceStep2.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  inherited;
  CanClose:=ValidateByResult(Validate,Clean,ModalResult);
end;

end.
