unit farray;

interface

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

type
  TfrmControlArray = class(TForm)
    picDisplay: TLabel;
    Label2: TLabel;
    optButton_0: TRadioButton;
    cmdAdd: TButton;
    cmdDelete: TButton;
    cmdClose: TButton;
    procedure OptButtonClick(Sender: TObject);
    procedure cmdAddClick(Sender: TObject);
    procedure cmdCloseClick(Sender: TObject);
    procedure cmdDeleteClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    nCtl:Integer;
  public
    { Public declarations }
  end;

var
  frmControlArray: TfrmControlArray;

implementation

{$R *.DFM}
uses VBFUNC;

procedure TfrmControlArray.OptButtonClick(Sender: TObject);
begin
  picDisplay.Color := QBColor (TControl(Sender).Tag + 1);
end;

procedure TfrmControlArray.cmdAddClick(Sender: TObject);
var
  rbOld, rbNew: TRadioButton;
begin
  if nCtl <= 0 then
    nCtl := 1
  else
    Inc(nCtl);

  if nCtl < 16 then
  begin
    rbOld := TRadioButton(FindComponent ('optButton_' + IntToStr (nCtl -1)));
    rbNew := TRadioButton.Create(Self);

    with rbNew do
    begin
      Parent := Self;
      SetBounds (rbOld.Left, rbOld.Top + rbOld.Height * 2,
                     rbOld.Width, rbOld.Height);
      Caption := 'Option' + IntToStr(nCtl + 1);
      Name := 'optButton_' + IntToStr(nCtl);
      Tag := nCtl;
      OnClick := optButtonClick;
    end;
  end;
end;

procedure TfrmControlArray.cmdCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmControlArray.cmdDeleteClick(Sender: TObject);
var
  rbWork:TRadioButton;
begin
  if nCtl > 0 then
  begin
    if nCtl > 15 then
      nCtl := 15;

    rbWork := TRadioButton(FindComponent ('optButton_' + IntToStr(nCtl)));

    if Assigned(rbWork) then
       rbWork.Free;

    Dec(nCtl);
    optButton_0.SetFocus;
  end;
end;

procedure TfrmControlArray.FormActivate(Sender: TObject);
begin
  AutoScroll := True;
end;

end.
