Recent

Author Topic: [SOLVED] like TRadioGroup but with individual Hints + all Buttons checkoff-able  (Read 1092 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 803
I'm searching for something like 'TRadioGroup', but with individual ToolTips for each RadioButton and all RadioButtons must be setable to 'off' (at the same time) programmatically.

I tried Event TRadioGroup.OnShowHint but this seems not to be fired at all (maybe this is the reason why it's not offered in the ObjectInspector).

I tried a combination of 1 TRadioGroup and some TRadioButtons, which allowes individual ToolTips, but I did not manage to set all RadioButtons to 'unchecked' at the same time (via code).

Same result with a combination of 1 TGroupBox and some TRadioButtons.

I'm on Linux Ubuntu 22.04 64-bit with Lazarus 2.0.10 / FPC 320.

Any idea for a workaround? Thanks in advance.
« Last Edit: June 03, 2024, 12:02:32 pm by Hartmut »

wp

  • Hero Member
  • *****
  • Posts: 12297
The TRadioGroup has a public array property Buttons exposing the RadioButtons contained in the group. You can use this to define individual hints by code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   RadioGroup1.Buttons[0].Hint := 'Item 1';
  4.   RadioGroup1.Buttons[1].Hint := 'Item 2';
  5.   RadioGroup1.Buttons[2].Hint := 'Item 3';
  6. end;

jamie

  • Hero Member
  • *****
  • Posts: 6529
Buttons are in the Trunk , not release it appears.

And also, you can set them all blank if you set the ItemIndex := -1

The control does have a OnShowHint event but its not published, at least not on the release.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12297
I see...

For release, a little hacky (assuming that no other controls have been added to the TRadioGroup):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   RadioGroup1.Controls[0].Hint := 'Item 1';
  4.   RadioGroup1.Controls[1].Hint := 'Item 2';
  5.   RadioGroup1.Controls[2].Hint := 'Item 3';
  6. end;
« Last Edit: June 03, 2024, 01:18:27 am by wp »

ASerge

  • Hero Member
  • *****
  • Posts: 2315
I'm searching for something like 'TRadioGroup', but with individual ToolTips for each RadioButton and all RadioButtons must be setable to 'off' (at the same time) programmatically.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnAllOffClick(Sender: TObject);
  2. begin
  3.   RadioGroup1.ItemIndex := -1;
  4. end;
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. var
  8.   i: SizeInt;
  9.   C: TControl;
  10. begin
  11.   RadioGroup1.Items.Text := 'Item 1' + LineEnding + 'Item 3' + LineEnding + 'Item 3';
  12.   RadioGroup1.ShowHint := True;
  13.   for C in RadioGroup1.GetEnumeratorControls do
  14.     C.Hint := 'Hint for ' + C.Caption;
  15. end;

Hartmut

  • Hero Member
  • *****
  • Posts: 803
@wp: Thank you very much for your 2 demos. I tried the 1st one in Lazarus 3.99, because it does not exist in Lazarus 2.x. It is a very interesting and powerful feature, which I would not have found without help. Your 2nd demo works in Lazarus 2.0.10 in my project perfectly.

@jamie: Thanks for this informations.

@ASerge: I tried your demo too and it works also in Lazarus 2.0.10 in my project. Thanks a lot.

 

TinyPortal © 2005-2018