unit DiagStep2;

interface

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

type
  TDiagramStep2 = class(TWizardTemplateForm)
    Label1: TLabel;
    GBBounds: TGroupBox;
    LLB: TLabel;
    LRB: TLabel;
    ELeftBound: TEdit;
    ERightBound: TEdit;
    Label4: TLabel;
    GBPoints: TGroupBox;
    SEPoints: TSpinEdit;
    procedure ELeftBoundExit(Sender: TObject);
    procedure ERightBoundExit(Sender: TObject);
    procedure SEPointsExit(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    function  Validate:Boolean;
    procedure Clean;
  public
    LeftBound,
    RightBound : double;
    function GoForward:Boolean;override;
    function GoBackward:Boolean;override;
  end;

var
  DiagramStep2: TDiagramStep2;

implementation

{$R *.DFM}

function TDiagramStep2.Validate;
begin
  Result:=
    ContainDouble(ELeftBound.Text,LeftBound,LLB.Caption) and
    ContainDouble(ERightBound.Text,RightBound,LRB.Caption) and
    CheckSpinContens(SEPoints,GBPoints.Caption);
  if(Result) then
  begin
    if(LeftBound>=RightBound) then
    begin
      Warning('Правая граница должна быть больше левой.');
      Result:=False;
      exit;
    end;
  end;
end;

procedure TDiagramStep2.Clean;
begin
  ELeftBound.Text:=ValidDouble(ELeftBound.Text);
  ERightBound.Text:=ValidDouble(ERightBound.Text);
  SEPoints.Value:=ValidInteger(SEPoints);
end;

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

function TDiagramStep2.GoBackward;
begin
  Clean;
  Result:=True;
end;

procedure TDiagramStep2.ELeftBoundExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(ELeftBound.Text,LeftBound,LLB.Caption)) then
    FocusControl(ELeftBound);
end;

procedure TDiagramStep2.ERightBoundExit(Sender: TObject);
begin
  inherited;
  if(not ContainDouble(ERightBound.Text,RightBound,LRB.Caption)) then
    FocusControl(ERightBound);
end;

procedure TDiagramStep2.SEPointsExit(Sender: TObject);
begin
  inherited;
  if(not CheckSpinContens(SEPoints,GBPoints.Caption)) then
    FocusControl(SEPoints);
end;

procedure TDiagramStep2.FormShow(Sender: TObject);
begin
  inherited;
  RightBound:=StrToFloat(ERightBound.Text);
  LeftBound:=StrToFloat(ELeftBound.Text);
end;

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

end.
