unit U_InputMark;

interface

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

type
  TF_InputMark = class(TForm)
    lng_Forms: TsiLangLinked;
    RzPanel1: TRzPanel;
    pnOkCancel: TRzPanel;
    btOk: TRzBitBtn;
    btCancel: TRzBitBtn;
    lbPrompt: TLabel;
    edValue: TRzEdit;
    RzCheckBox1: TRzCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ValCh(Sender: TObject);

  private
    GForm: TForm;
  public
    Constructor Create(AOwner: TComponent; AForm: TForm);
    Destructor Destroy; override;
    function Execute(const ACaption, APrompt: String): Integer;
  end;

  function InputMark(const ACaption, APrompt: String; var AVal: String): Integer;

var
  F_InputMark: TF_InputMark;

implementation

{$R *.dfm}

constructor TF_InputMark.Create(AOwner: TComponent; AForm: TForm);
begin
  GForm := AForm;
  RzCheckBox1.Caption := cmAutoLabel_caption;
  inherited Create(AOwner);
end;

destructor TF_InputMark.Destroy;
begin
  inherited;
end;

procedure TF_InputMark.ValCh(Sender: TObject);
begin
  F_InputMark.RzCheckBox1.Checked := false;
end;

function TF_InputMark.Execute(const ACaption, APrompt: String): Integer;
begin
  Result := -1;
  Caption := ACaption;
  if APrompt <> '' then
    lbPrompt.Caption := APrompt;
  RzCheckBox1.Caption := cmAutoLabel_caption;
  Result := ShowModal;
  //Tolik 09/02/2022 --
  if Result = mrOk then
  begin
    if RzCheckBox1.Checked then
      Result := mrIgnore;
  end;
  //
end;

procedure TF_InputMark.FormCreate(Sender: TObject);
begin
  edValue.Text := '';
end;

procedure TF_InputMark.FormShow(Sender: TObject);
begin
  edValue.SetFocus;
end;

function InputMark(const ACaption, APrompt: String; var AVal: String): Integer;
begin
  if F_InputMark = nil then
    F_InputMark := TF_InputMark.Create(Application, nil);
  //Tolik 14/02/2022
  F_InputMark.edValue.OnChange := nil;
  F_InputMark.edValue.Text := AVal;
  F_InputMark.edValue.OnChange := F_InputMark.ValCh;
  Result := F_InputMark.Execute(ACaption, APrompt);
  if Result = mrOk then
    AVal := F_InputMark.edValue.Text;
end;

end.