unit U_InputRadio;

interface

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

type
  TF_InputRadio = class(TForm)
    lng_Forms: TsiLangLinked;
    RzPanel1: TRzPanel;
    pnOkCancel: TRzPanel;
    btOk: TRzBitBtn;
    btCancel: TRzBitBtn;
    rgValues: TRzRadioGroup;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    procedure rgValuesChanging(Sender: TObject; NewIndex: Integer;
      var AllowChange: Boolean);
  private
    GForm: TForm;
    FDefItems: string;
    FDisableItem1: boolean;
  public
    Constructor Create(AOwner: TComponent; AForm: TForm);
    Destructor Destroy; override;
    function Execute(const ACaption, APrompt: String): Integer;
  end;

  function InputRadio(const ACaption, APrompt: String; aValues: TStrings; ASelIdx: Integer=1; aDisableItem1: boolean = False): Integer;

var
  F_InputRadio: TF_InputRadio;

implementation

{$R *.dfm}

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

destructor TF_InputRadio.Destroy;
begin
  inherited;
end;

function TF_InputRadio.Execute(const ACaption, APrompt: String): Integer;
begin
  Result := -1;
  Caption := ACaption;
  rgValues.Caption := APrompt;

  if ShowModal = mrOk then
    Result := rgValues.ItemIndex;
end;

function InputRadio(const ACaption, APrompt: String; aValues: TStrings; ASelIdx: Integer=1; aDisableItem1: boolean = False): Integer;
begin
  if F_InputRadio = nil then
  begin
    F_InputRadio := TF_InputRadio.Create(Application, nil);
    F_InputRadio.FDefItems := F_InputRadio.rgValues.Items.Text;
  end;
  F_InputRadio.rgValues.OnChanging := nil;
  F_InputRadio.FDisableItem1 := aDisableItem1;

  if aValues <> nil then
  begin
    F_InputRadio.rgValues.Items.Clear;
    F_InputRadio.rgValues.Items.AddStrings(aValues);
  end
  else
  begin
    F_InputRadio.rgValues.Items.Clear;
    F_InputRadio.rgValues.Items.Text := F_InputRadio.FDefItems;
  end;
  F_InputRadio.rgValues.ItemIndex := ASelIdx;
  if F_InputRadio.FDisableItem1 then
  begin
    if ASelIdx = 0 then
      F_InputRadio.rgValues.ItemIndex := 1;
  end;
  F_InputRadio.rgValues.OnChanging := F_InputRadio.rgValuesChanging;
  Result := F_InputRadio.Execute(ACaption, APrompt);
end;

procedure TF_InputRadio.rgValuesChanging(Sender: TObject;
  NewIndex: Integer; var AllowChange: Boolean);
begin
  AllowChange := True;
  if FDisableItem1 then
    if NewIndex = 0 then
      AllowChange := False;
end;

end.