unit ParamUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TParamForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    AdaptiveRButton: TRadioButton;
    LinearRButton: TRadioButton;
    procedure KeyPressed(Sender: TObject; var Key: Char);
    procedure KeyPressedDeci(Sender: TObject; var Key: Char);
    procedure AdaptiveRButtonClick(Sender: TObject);
    procedure LinearRButtonClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    constructor Create(AOwner: TComponent; Param: Word); reintroduce;
  end;

implementation

{$R *.dfm}

constructor TParamForm.Create(AOwner: TComponent; Param: Word);
begin
  inherited Create(AOwner);
  case Param of
    0 : Exit;
    1 : LinearRButton.Enabled:=False;
    2 : begin
          LinearRButton.Checked:=True;
          AdaptiveRButton.Enabled:=False;
          Edit1.Enabled:=False;
          Label1.Enabled:=False;
        end;
  end;
  Button1.ModalResult:=mrNone;
end;


procedure TParamForm.KeyPressed(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', #8]) then
    Key:=#0;
end;


procedure TParamForm.KeyPressedDeci(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', #8, ',']) or ((Key = ',') and (Pos(Key, (Sender as TEdit).Text) <> 0)) then
    Key:=#0;
end;


procedure TParamForm.AdaptiveRButtonClick(Sender: TObject);
begin
  Edit1.Enabled:=True;
  Label1.Enabled:=True;
end;


procedure TParamForm.LinearRButtonClick(Sender: TObject);
begin
  Edit1.Enabled:=False;
  Label1.Enabled:=False;
end;


procedure TParamForm.Button1Click(Sender: TObject);
var Dir: Integer;
    Dis, Sig: Double;
begin
  if AdaptiveRButton.Checked then begin
    Dir:=StrToInt(Edit1.Text);
    if Dir = 0 then begin
      ShowMessage('Počet směrů nesmí být 0.');
      Edit1.SetFocus;
      Exit;
    end;
    if Dir > 128 then begin
      ShowMessage('Počet směrů smí být maximálně 128.');
      Edit1.SetFocus;
      Exit;
    end;
  end;

  Dis:=StrToFloat(Edit2.Text);
  if Dis <= 0.5 then begin
    ShowMessage('Vzdálenost 0,5 nebo menší v obrazu nezpůsobí změny.');
    Edit2.SetFocus;
    Exit;
  end;
  if Dis > 128 then begin
    ShowMessage('Vzdálenost smí být maximálně 128.');
    Edit2.SetFocus;
    Exit;
  end;

  Sig:=StrToFloat(Edit3.Text);
  if Sig = 0 then begin
    ShowMessage('Sigma nesmí být 0.');
    Edit3.SetFocus;
    Exit;
  end;

  ModalResult:=mrOk;
end;


procedure TParamForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

end.
