unit U_InputRange;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  U_LNG, siComp, siLngLnk, RzButton, Mask, RzEdit, ExtCtrls, RzPanel;

type
  TF_InputRange = class(TForm)
    lng_Forms: TsiLangLinked;
    RzPanel1: TRzPanel;
    lbCoordz: TLabel;
    lbHeight: TLabel;
    neFrom: TRzNumericEdit;
    neTo: TRzNumericEdit;
    pnOkCancel: TRzPanel;
    btOk: TRzBitBtn;
    btCancel: TRzBitBtn;
    lbPrompt: TLabel;
    procedure neFromChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    
  private
    GForm: TForm;
  public
    Constructor Create(AOwner: TComponent; AForm: TForm);
    Destructor Destroy; override;
    function Execute(const ACaption, APrompt: String): Boolean;
  end;

  function InputRange(const ACaption, APrompt: String; var AFrom, ATo: Integer): Boolean;

var
  F_InputRange: TF_InputRange;

implementation

{$R *.dfm}

constructor TF_InputRange.Create(AOwner: TComponent; AForm: TForm);
begin
  GForm := AForm;
  inherited Create(AOwner);
end;

destructor TF_InputRange.Destroy;
begin
  inherited;
end;

function TF_InputRange.Execute(const ACaption, APrompt: String): Boolean;
begin
  Result := false;
  Caption := ACaption;
  lbPrompt.Caption := APrompt;

  //neFrom.Value := 1;
  //neTo.Value := 1;
  if ShowModal = mrOk then
  begin
    Result := true;
  end;
end;

procedure TF_InputRange.FormCreate(Sender: TObject);
begin
  neFrom.Value := 1;
  neTo.Value := 1;
end;

procedure TF_InputRange.neFromChange(Sender: TObject);
begin
  neTo.Value := neFrom.Value;
end;


function InputRange(const ACaption, APrompt: String; var AFrom, ATo: Integer): Boolean;
begin
  if F_InputRange = nil then
    F_InputRange := TF_InputRange.Create(Application, nil);

  AFrom := 1;
  ATo := 1;

  F_InputRange.neFrom.IntegersOnly := true;
  F_InputRange.neTo.IntegersOnly := true;
  Result := F_InputRange.Execute(ACaption, APrompt);
  if Result then
  begin
    AFrom := F_InputRange.neFrom.IntValue;
    ATo := F_InputRange.neTo.IntValue;
  end;
end;

end.