Source Code



Access the controls of a TRadioGroup

  • anonymous
  • Dec 16' 13
  • Delphi
  • 199
  • 176
  • United States

How to access the controls of a TRadioGroup

 

procedure RGB_EnableItem(RadioGroup: TRadioGroup; ItemIndex: Byte; bEnabled: Boolean);
begin
  RadioGroup.Controls[ItemIndex].Enabled := bEnabled;
end;

// Example: Deactivates the 2. Item  (Index starts at 0)

procedure TForm1.Button1Click(Sender: TObject);
begin
  RGB_EnableItem(RadioGroup1, 1, False);
end;


{2. *******************************************************}
procedure RGB_ShowItem(RadioGroup: TRadioGroup; ItemIndex: Byte; bVisible: Boolean);
begin
  RadioGroup.Controls[ItemIndex].Visible := bVisible;
end;

// Example: Hides the 2. Item  (Index starts at 0)
procedure TForm1.Button2Click(Sender: TObject);
begin
  RGB_ShowItem(RadioGroup1, 1, False);
end;


{3. *******************************************************}
// Show Hints for TRadioGroup items
procedure TForm1.Button3Click(Sender: TObject);
var
  i: Byte;
begin
  for i := 0 to RadioGroup1.ControlCount - 1 do
  begin
    RadioGroup1.Controls[i].ShowHint := True;
    RadioGroup1.Controls[i].Hint := (Radiogroup1.Controls[i] as TRadiobutton).Caption;
  end;
end;

{4. *******************************************************}
// Focus a specified Radiobutton in a TRadioGroup
procedure RGB_FocusItem(RadioGroup: TRadioGroup; ItemIndex: Byte);
var
  RadiogroupClick: TNotifyEvent;
begin
  if ItemIndex = 0 then
  begin
    RadioGroup.OnClick := nil;
    (RadioGroup.Controls[1] as TRadiobutton).SetFocus;
    RadioGroup.OnClick := RadiogroupClick;
  end;
end;

// Example: Focus the 2. Radiobutton
procedure TForm1.Button4Click(Sender: TObject);
begin
  RGB_FocusItem(RadioGroup1, 1);
end;

 

enjoy code

  • Tags : delphi, radio button, TRadioGroup
comments powered by Disqus

Related Code

fairly nominal



Category